Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Aspect broke ErrorMvcAutoConfiguration #6431

Closed
liudongqing opened this issue Jul 20, 2016 · 4 comments
Closed

Add new Aspect broke ErrorMvcAutoConfiguration #6431

liudongqing opened this issue Jul 20, 2016 · 4 comments

Comments

@liudongqing
Copy link

liudongqing commented Jul 20, 2016

I am using spring boot 1.3.6, I tried to implement a Access control Aspect to apply to the controller, but after the Aspect added, it broke the startup of the embedded tomcat. The error is following.

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties; nested exception is java.lang.IllegalArgumentException: Can not set org.springframework.boot.autoconfigure.web.ServerProperties field org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties to com.sun.proxy.$Proxy53

See full log here.

I created a simple project to reproduce it. could someone please check it out ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 20, 2016
@wilkinsona
Copy link
Member

It looks to me like your pointcut is too broad and it's causing everything to be proxied so that your aspect can be applied to it. It looks like you're trying to add some advice to all methods/classes that are annotated with @AclRequired. If so, this might help: http://stackoverflow.com/questions/2011089/aspectj-pointcut-for-all-methods-of-a-class-with-specific-annotation

If that's not the case, please clarify what you're trying to do.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 20, 2016
@liudongqing
Copy link
Author

Thanks for quick response! I changed it to @pointcut("@annotation(com.wuyouz.AclRequired)") and it works. I am confused.

In spring aop doc, it says

@target - limits matching to join points (the execution of methods when using Spring AOP) where the class of the executing object has an annotation of the given type

I only put @AclRequired annotation in controller methods, why it will impact on other classes in spring boot?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 20, 2016
@wilkinsona
Copy link
Member

That's really an AspectJ question as that's what Spring's using to determine whether or not the pointcut matches.

The key difference is that @target matches the runtime type whereas @annotation matches the statically declared type. Because you're using @target AspectJ can't be certain that the pointcut won't match at runtime (AspectJ can be used at compile time) so it indicates that the pointcut maybe matches. However, I'd expect Spring to map this maybe to false do to this logic in AspectJExpressionPointcut:

// A match test returned maybe - if there are any subtype sensitive variables
// involved in the test (this, target, at_this, at_target, at_annotation) then
// we say this is not a match as in Spring there will never be a different
// runtime subtype.
RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch);
return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass));

You are using @target so there is a subtype sensitive variable involved and I'd expect false to be returned. However, that doesn't happen. I suspect that this is a bug and I can reproduce it without Spring Boot being in the picture. I've opened SPR-14494.

@wilkinsona wilkinsona removed the status: feedback-provided Feedback has been provided label Jul 20, 2016
@liudongqing
Copy link
Author

@wilkinsona Thanks a lot! I am using @annotation for now and it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants