Questions tagged [spring-aspects]

common utility aspects to use when creating systems with [spring-aop]

129 questions
51
votes
3 answers

spring autowired aop circular dependency

I'm using java config with @ComponentScanin order to initialize my beans and @EnableAspectJAutoProxy(proxyTargetClass=true)to use cglib proxies. In this project we have a lots of generated services autowired between them using @Autowired. It works…
Ignasi
  • 5,887
  • 7
  • 45
  • 81
18
votes
2 answers

Spring AOP Exclude Some Classes

I'm using Spring AspectJ for logging method execution statistics, however, I want to exclude some classes and methods from this without changing the pointcut expression. To exclude certain methods I created a custom annotation which I use to filter…
Harshil Sharma
  • 2,016
  • 1
  • 29
  • 54
14
votes
8 answers

Get all exceptions in Java and send them remotely

I have a huge Java application. I want to intercept all Java Exceptions and send them by e-mail. I can't add everywhere code for sending the code via try-catch so is it possible to use for example Aspect to intercept the exception into low level…
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
12
votes
4 answers

Aspect not being called in Spring test

I am using Spring 4.16 and i have my ValidationAspect, which validates methods arguments and throws ValidationException if is something wrong. This is being called when i run the server and send requests, but not when comes from the test: package…
jscherman
  • 5,839
  • 14
  • 46
  • 88
11
votes
1 answer

How to load a custom DaoAuthenticationProvider into the Spring Context?

I have this issue with Spring Security. I have a java-config implementation with a SecurityConfig class, that extends WebSecurityConfigurerAdapter. In this class I want to override the method…
Alessandro C
  • 3,310
  • 9
  • 46
  • 82
11
votes
2 answers

Retrieve parameter value from ProceedingJoinPoint

In my Request i have a parameter name "accessToken", how do i get request parameter value from ProceedingJoinPoint ? public Object handleAccessToken(ProceedingJoinPoint joinPoint) throws Throwable { final Signature signature =…
Shamseer PC
  • 787
  • 2
  • 9
  • 20
9
votes
1 answer

Using AspectJ LTW to allow spring proxy functionalty on self-invocation of non-public methods and related considerations

I have seen numerous examples of Spring functionality related to @Cacheable, @Transactional, @Async, etc. where the same options are reiterated every time: Self invocation made through a proxy object gotten through either the…
filpa
  • 3,651
  • 8
  • 52
  • 91
8
votes
1 answer

@Transactional does not work when @Validated

If I add @Validated annotation to interface/implementation of my service then the service is not transactional anymore. Stacktrace shows there is no TransactionInterceptor but I see only MethodValidationInterceptor. If I remove @Validated then I see…
Marek Raki
  • 3,056
  • 3
  • 27
  • 50
7
votes
2 answers

How to intercept each method call within given method using Spring AOP or AspectJ

class Test { @override public String a(){ b(); d(); } private String b() { c(); } private String c(){ d(); } private String d(){} } I want to intercept each methods of class Test that is been called from overridden method A() and want to know…
Crazy-Coder
  • 107
  • 1
  • 1
  • 9
7
votes
1 answer

spring testing @async method

I'm trying to test if @Async annotation of Spring is working as expected on my project. But It doesn't. I have this test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = GlobalConfiguration.class) public class…
Ignasi
  • 5,887
  • 7
  • 45
  • 81
5
votes
2 answers

Dependency Injection into Spring non-managed beans

I have a JPA domain class that is non managed. It is instantiated via the new operator. UserAccount account = new UserAccount(); userRepository.save(account) In my UserAccount class, I have a beforeSave() method which is dependent on my…
sparkyspider
  • 13,195
  • 10
  • 89
  • 133
5
votes
1 answer

spring aop - chaining multiple aspects

i have two aspects, one for acquiring a lock @Around a call, another one for debouncing method calls. the aspects look like this: @Pointcut("execution(public * * (..))") private void anyPublicMethod() {} @Around("anyPublicMethod() &&…
rmalchow
  • 2,689
  • 18
  • 31
4
votes
1 answer

Load time weaving for non-spring beans in a spring application

I have a spring boot application with some REST controllers, service classes and helper classes. The controllers and service classes are spring managed while helper classes are not spring managed and mostly contain static methods. The AspectJ…
Avi
  • 1,070
  • 1
  • 15
  • 28
4
votes
3 answers

How do you ignore AspectJ compiler warnings for certain aspects with Maven

If you use the AspectJ compiler with an Aspect library such as Springs and you do not have any classes that match a particular Aspect you get: [WARNING] advice defined in org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect has not been…
Adam Gent
  • 47,843
  • 23
  • 153
  • 203
4
votes
2 answers

Can not build MockMvc (There is already handler of type X mapped)

I have simple Controller class: @Controller public class UserController { @RequestMapping("/user") @ResponseBody @PostAuthorize("hasPermission(returnObject, 'VIEW')") public User getUser(Long id) { // fetch user from DB …
fracz
  • 20,536
  • 18
  • 103
  • 149
1
2 3
8 9