spring-aop

Listing Aspect-proxied beans in Spring

[亡魂溺海] 提交于 2019-12-08 00:31:10
问题 Is there a way to get the list of beans proxied with a specific Aspect by Spring? We have an aspect on some beans that stopped working, and we are trying to figure out what happened, so I created a class to scan the ApplicationContext after it has been loaded @Component public class AspectScanner implements ApplicationListener<ContextRefreshedEvent> { public static final Logger LOGGER = LoggerFactory.getLogger(AspectScanner.class); @Override public void onApplicationEvent

Spring AOP not working for Feign Client

风流意气都作罢 提交于 2019-12-07 16:19:47
问题 I having an aop-setup @Target({ElementType.METHOD}) @Retention(value = RetentionPolicy.RUNTIME) public @interface IgnoreHttpClientErrorExceptions { } @Aspect @Component public class IgnoreHttpWebExceptionsAspect { @Around(value = "@annotation(annotation)", argNames = "joinPoint, annotation") public Object ignoreHttpClientErrorExceptions(ProceedingJoinPoint joinPoint, IgnoreHttpClientErrorExceptions annotation) throws Throwable { try { //do something } catch (HttpClientErrorException ex) { /

Whats the best way to inject same instance of service in service for Spring AOP

你说的曾经没有我的故事 提交于 2019-12-07 14:44:22
问题 I'va a ServiceImpl with is annotated with @Service stereotype of Spring and have two methods in it each one is annotated with custom annotations which are intercepted by Spring. @Service public class ServiceImpl implements Service{ @CustomAnnotation public void method1(){ ... } @AnotherCustomAnnotation public void method2(){ this.method1(); ... } } } Now Spring uses proxy based AOP approach and hence as I'm using this.method1() interceptor for @CustomAnnotation will not able to intercept this

Aop Annotation at Spring Controllers Doesn't Work

五迷三道 提交于 2019-12-07 12:32:13
问题 I have made an annotation for aop. When I use it at any method rather than controller methods it works well. However when I use it at my controller's methods my controller stops working. It starts to give 404 not found error for mappings. I found a similar question here: Spring 3 MVC @Controller with AOP interceptors? but I don' know how to do it. My method at my controller is that: @WebAuditable // This is my annotation that works at other methods @Override @RequestMapping(value = "/ad",

Spring - Injecting resources in per-scoped (perthis - pertarget) aspect

自古美人都是妖i 提交于 2019-12-07 10:43:32
问题 In my Spring web application, I'm trying to inject a resource in a perthis-scoped AspectJ aspect. Injection works well using a singleton aspect, but fails using a perthis scoped one. I tried using both @Autowire annotation or xml <property> tag. Here is my code. Aspect (for @Configurable I tried both autowire=Autowire.BY_TYPE and autowire=Autowire.BY_NAME ): @Aspect( "perthis(org.mypackage.aop.aspects.TestAspect.participateAroundPointcut())") @Component @Scope("prototype") @Configurable()

Implementing dynamic menu for Spring MVC/AOP application

偶尔善良 提交于 2019-12-07 08:20:21
问题 I wish to implement dynamically changeable menu (updating whenever annotated method or controller added) for my Spring MVC application. What i want is to introduce new annotation ( @RequestMenuMapping ) which will go to @Controller beans and their methods (just like @RequestMapping works). Heres is what i want, User class, producing menu like Users Index | List | Signup | Login with following code: @Controller @RequestMapping("user") @RequestMenuMapping("Users") public class User {

Spring AOP creates extra bean

折月煮酒 提交于 2019-12-07 07:37:35
问题 I 'm playing with Spring AOP. Here is a simple class public class CModel extends Car { private double torqueMeasure = 1; public CModel() { System.out.println(" C-Model constructor"); } } And Spring configuration is like this <aop:config> <aop:aspect ref="audit"> <aop:before pointcut="execution(* com.test.main..*(..))" method="firstControl"/> ... </aop:aspect> </aop:config> Ok now; when i add aop:config and intercepts CModel then Spring calls CModel constructor twice. It means Spring creates 2

Spring-AOP load-time weaving on 3rd-party classes

倾然丶 夕夏残阳落幕 提交于 2019-12-07 06:08:37
I wrote an aspect that I'm trying to test with junit. The aspect has an @Around advice on a 3rd party method called setQuery . At compile time it complains: Can't find referenced pointcut setQuery Here's my aspect: @Component @Aspect public class ElasticsearchQuerySecurityAspect { @Around("org.elasticsearch.action.search.SearchRequestBuilder.setQuery() && args(queryBuilder)") public void addFilter(final ProceedingJoinPoint pjp, QueryBuilder queryBuilder) throws Throwable { Object[] args = pjp.getArgs(); // Set the filter to use our plugin FilterBuilder securityFilter = FilterBuilders

Which Interface's (extending CrudRepository) delete method was triggered using spring AOP?

故事扮演 提交于 2019-12-07 03:04:26
@Repository public interface UserRepository extends JpaRepository<User, Long> { } I am calling userRepo.deleteById(1) from my service layer and using spring AOP I want to log the Interface name whenever any deleteById is called so that I can track which interface's deleteById was triggered. I want an output which can give me a clue of the interface name. joinPoint.getSignature() returns the generic name i.e. void org.springframework.data.repository.CrudRepository.deleteById(Object) and but I want to see UserRepository or any repository name whose deleteById was called. Will this help ? @Before

Spring Data Rest Override Repositories (Controllers vs AOP)

放肆的年华 提交于 2019-12-07 01:58:34
Domain/Repository Project { User owner; } //Querydsl repositories @RepositoryRestResource public interface ProjectRepository extends PagingAndSortingRepository<Project, Long>, QueryDslPredicateExecutor<Project>, QuerydslBinderCustomizer<QProject> { default void customize(QuerydslBindings bindings, QProject project) { (...) } } Requeriment: filter data according to the authenticated user context: If user is ROLE_PUBLIC show projects according predicate and where user is the owner . If user is ROLE_ADMIN show projects according predicate filter. I tried solved throught several alternatives: