@EnableAspectJAutoProxy,@Aspect and @RestController

See original GitHub issue

Hi,

I use Spring-boot since few months and it’s absolutely great but I have some problems with the association @EnableAspectJAutoProx, @Aspect and @RestController.

If I declare @EnableAspectJAutoProxy and a java bean with @RestController, nothing to add, it works great.

On the other side, if I add a @Aspect with a pointcut matching the bean with @RestController, I have no more request mapping. When I looked the debug output, the logger RequestMappingHandlerMapping is quiet, the request is not performed because the mapping is not registered. For info, the bean with the @RestController is an implementation of a simple java Interface and the EnableAspectJAutoProxy use the default interface-based JDK proxy approach.

Stéphane

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
wilkinsonacommented, Sep 9, 2014

Thanks.

Your controller implements an interface and, as described in the Spring AOP documentation this means that an interface-based proxy is created. It’s this proxy that is inspected for @RequestMapping methods and none are found as there are none on the interface.

You can fix the problem by forcing the creation of class proxies:

@Configuration
@EnableAutoConfiguration
@ComponentScan
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class AppConfig {

}
2reactions
scizeroncommented, Jun 26, 2017

Hello, I uploaded a sample project, You can try it : https://github.com/scizeron/test.git. At the begining, the @Aspect is disabled, all is ok (200 OK) Afterwards, you can enable the @Aspect and you will have a 404 Not Found. Check the README for more details. Thx for all Stéphane

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring AOP Example Tutorial - Aspect, Advice, Pointcut ...
Add aop:aspectj-autoproxy element to enable Spring AspectJ support with auto proxy at runtime; Configure Aspect classes as other Spring beans.
Read more >
Spring 4 AOP @Aspect isn't triggering for @RestController
This exact aspect works when I change the execution pattern to match services and place it in my service package. The Aspect and...
Read more >
EnableAspectJAutoProxy (Spring Framework 6.0.2 API)
Enables support for handling components marked with AspectJ's @Aspect annotation, similar to functionality found in Spring's <aop:aspectj-autoproxy> XML ...
Read more >
AOP in Spring Boot, is it a JDK dynamic proxy or a Cglib ...
@Configuration @ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class }) @ConditionalOnProperty(prefix ...
Read more >
Core Spring 4.2 Certification Mock Exam | Java & Moi
Given the following Spring configuration file, what is the correct answer: ... Use <aop:aspectj-autoproxy /> to enable detection of @Aspect bean.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found