Frage

I'm trying to change from load-time-weaving to compile-time-weaving with my Spring 2.5 app.

To do this, I did the following:

  1. In my ant build file, I added

    <path id="aspectPath">
        <pathelement location="${lib.home}/spring-aspects.jar"/>
    </path>
    
    <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
        <classpath>
            <pathelement location="${aspectj.home}/aspectjtools.jar"/>
        </classpath>
    </taskdef>
    

and replaced the reference to the javac compiler with the following

    <iajc sourceroots="${src.home}" 
        destdir="${build.home}/WEB-INF/classes" 
        classpathRef="compile.classpath" 
        aspectPathRef="compile.classpath" 
        debug="${compile.debug}" 
        deprecation="${compile.deprecation}" 
        encoding="cp1252" 
        source="1.6" 
        target="1.6" 
        showWeaveInfo="${compile.debug}"/>

In applicationContext.xml I then replaced

<context:load-time-weaver/>

with

<context:spring-configured/>

Other configuration settings in my app context file, BTW, include

<tx:annotation-driven/>
<context:component-scan base-package="com.domain.somepackage"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

In the context.xml file, I removed the following from the loader tag

loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"

When I run the build script, it compiles without errors.

I do get this warning however.

[iajc] warning at <Unknown>::0 Found @DeclareAnnotation while current release 
does not support it (see 'org.aspectj.weaver.bcel.AtAjAttributes') 

at the top, and this warning at the bottom:

[iajc] warning at C:\server-
lib\aspectjtools.jar!org\aspectj\ajdt\internal\compiler\
CompilerAdapter.class:121::0 advice defined in    
org.aspectj.ajdt.internal.compiler.CompilerAdapter has not been 
applied [Xlint:adviceDidNotMatch]

Most of the logging looks like:

[iajc] weaveinfo Join point 'method-execution(void com.kjconfigurator.upgra
de.Upgrade1_07HelperImp.addServiceParticipation(com.kjconfigurator.core.domain.U
ser, com.kjconfigurator.core.domain.ServiceAccount))' in Type 'com.kjconfigurato
r.upgrade.Upgrade1_07HelperImp' (Upgrade1_07HelperImp.java:196) advised by after
Returning advice from 'org.springframework.transaction.aspectj.AnnotationTransac
tionAspect' (spring-aspects.jar!AbstractTransactionAspect.class:77(from Abstract
TransactionAspect.aj))

I removed the tomcatspringweaver jar from the tomcat lib. I am using aspectj1.7

When I start the app up, I get an error indicating that when a dao class is being injected into a service class there is an NPE at at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:104)

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are: PropertyAccessException 1: 
org.springframework.beans.MethodInvocationException: Property 'dao' threw exception; 
nested exception is java.lang.NullPointerException

The Dao class extends an AbstractJpaDao class that looks like this:

public abstract class AbstractJpaDao<T>  {
    private static Logger log = Logger.getLogger(AbstractJpaDao.class.getName());

    private EntityManager entityManager;

    @PersistenceContext
    public void setEntityManager(EntityManager entityManager) {
        this. entityManager = entityManager;
    }
    ...
}

It's been such a long time since all this was initially set up, I don't remember how all the configurations work. Nor do I understand class loaders or AspectJ very well. But something is not happening correctly, perhaps the Entitymanager is not being injected for some reason.

Questions.

  1. What might be causing this?
  2. Is <context:spring-configured/> really needed?
  3. The package referenced by <context:component-scan base-package="com.domain.somepackage"/> does not include the Dao class in question. When I do add another component-scan tag with the dao's package in it, nothing different happens. Is this necessary?
War es hilfreich?

Lösung 2

I finally found a solution to this problem with the help of a Spring consultant.

There was an aspect that was being called before it was fully initialized resulting in an NPE in the aspect. (Eclipse incorrectly showed the NPE originating in the class that was being advised.) I disabled the aspect by removing the annotations because the aspect was not critical; however, a better fix would have been for me to instruct Spring to initialize that class ahead of the others, or use a point cut expression that was more narrow and which excluded setter methods.

Andere Tipps

Do you have any schedule tasks defined somewhere - it sounds like the scheduled tasks are getting triggered before the Spring context is completely initialized.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top