1

我试图从加载时间编织到编译时间编织与我的Spring 2.5应用程序。从加载时间编织器到编译时间编织器在春天的问题

要做到这一点,我做了以下内容:

  1. 在我的Ant构建文件,我添加

    <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> 
    

,取而代之的是以下

的参考javac编译
<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}"/> 

在applicationCont ext.xml我再换成

<context:load-time-weaver/> 

在我的应用程序上下文文件

<context:spring-configured/> 

其他配置设置,BTW,包括

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

在context.xml文件,我删除了从装载机标签开始追踪

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

当我运行构建脚本时,它编译没有错误。

但是我得到这个警告。

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

在顶部,此警告在底部:

[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] 

大部分记录的样子:

[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)) 

我删除从Tomcat的lib的tomcatspringweaver罐子。 我使用aspectj1.7

当我启动应用程序时,我得到的指示是,当一个DAO类被注入到服务类有一个NPE处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 

在DAO类延伸的AbstractJpaDao类,看起来像这样:

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; 
    } 
    ... 
} 

它已经这么长的时间,因为这一切的初始设置后,我不不要忘记一切配置工作。我也不太了解班级装载机或AspectJ。但是有些事情没有正确发生,也许Entitymanager没有被注入是因为某种原因。

问题。

  1. 什么可能导致这种情况?
  2. 是否真的需要<context:spring-configured/>
  3. <context:component-scan base-package="com.domain.somepackage"/>引用的包不包含Dao类。当我在其中添加另一个组件扫描标签时,没有什么不同。这是必要的吗?

回答

0

我终于在春季顾问的帮助下找到了解决这个问题的办法。

在完全初始化之前有一个方面被调用,导致NPE在这方面。 (Eclipse错误地显示了NPE源于被建议的类。)我通过删除注释来禁用该方面,因为该方面并不重要;然而,更好的解决办法是让我指示Spring先于其他人初始化该类,或者使用更窄的点删除表达式,并排除了setter方法。

0

是否有任何计划任务定义在某处 - 这听起来像计划任务在Spring上下文完全初始化之前触发。

+0

你好,谢谢你的回答。通过计划任务,你的意思是触发器连接到org.springframework.scheduling.quartz.SchedulerFactoryBean的实例吗?我确实有一些,但是我禁用了它们,重新编译了,并且在加载上下文时遇到了同样的问题。 – Ceniza