This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Adding spring-aspects causes compilation errors

Apr 13th, 2011, 03:11 PM

Hey all, I've been using Spring and Spring AOP (dynamic proxies) for a long time, but I'm just now looking at tossing some bytecode weaving into the mix. Right now, I'm trying to get a basic @Configurable object to work--i.e. be injectable by Spring when instantiated outside of Spring. I have a simple project set up using Maven and the aspectj-maven-plugin for build-time weaving. I have two simple classes. One has a main method, and one is an aspect with a pointcut that prints to stdout when that main method executes. I can compile and run this simple example just fine. As soon as I add org.springframework:spring-aspects--it seems to need to be an "aspectLibrary" in the plugin's configuration as well as a project dependency--I get this compilation error:
[ERROR] can't determine superclass of missing type org.springframework.transaction.interceptor.Transa ctionAspectSupport
when batch building BuildConfig[null] #Files=2 AopXmls=#0
[Xlint:cantFindType]

That looks to me like something from spring-tx, so I add that as a dependency, and then I get:
[ERROR] can't determine annotations of missing type javax.persistence.Entity
when weaving type com.bar.SomeBean
when weaving classes
when weaving
when batch building BuildConfig[null] #Files=2 AopXmls=#0
[Xlint:cantFindType]

After I add org.hibernate.javax.persistence:hibernate-jpa-2.0-api, it's back to working. Surely I'm doing something wrong here. Do I seriously have to have spring-tx and JPA on my classpath just to be able to use @Configurable?

I've found that there's a compiler option to change the level of "can't find type" errors. It seems that it can only be set using the aspectj compiler's -Xlintfile option and providing a properties file that overrides the defaults. You add the property cantFindType = warning, and it changes from a compiler error to a warning, letting the compilation go ahead. Does anyone know how to do something like this in the aspectj maven plugin? It seems to only support "-Xlint", which only seems to be able to set coarse-grained error checking options and not specifically change the level of a particular check.