实体管理器尚未注入:是将Spring Aspects JAR配置为AJC/AJDT方面的库吗?
我想写一个简单的春天休息Web服务,因为我不熟悉Maven(并且因为Maven通常不能完成任务 - 连接问题),所以我现在尝试构建Ant。现在,构建可以,服务可以运行。但是,如果持续功能被触发时,系统会提示:实体管理器尚未注入:是将Spring Aspects JAR配置为AJC/AJDT方面的库吗?
01:48:39 Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'uncaughtException'; model is {exception=java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)} -org.springframework.web.servlet.DispatcherServlet
java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)
at com.books.domain.UserInfo.entityManager(UserInfo.java:96)
at com.books.domain.UserInfo.findUserByNamePassword(UserInfo.java:157)
at com.books.web.UserController.register(UserController.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
我的蚂蚁的build.xml:
<target name="compile" depends="init" description="compile the source ">
<!--<javac srcdir="${src}"
debug="on"
destdir="${build}"
classpathref="compile.classpath"
includeantruntime="false"/>-->
<iajc source ="1.6" target="1.6" sourceroots="src/main/java" destDir="src/main/webapp/WEB-INF/classes" showweaveinfo="true" verbose="true">
<classpath>
<path refid="compile.classpath"/>
<path refid="aspectj.classpath"/>
</classpath>
</iajc>
</target>
我的applicationContext.xml:
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="dataSource" ref="dataSource"/>
</bean>
任何帮助将高度赞赏。谢谢!
使用ROO和maven pom解决了此问题。关于如何使用Ant构建的信息太少。
我做了一个roven项目的maven-free ant build,如果有人想要一个解决方案,我可以写一个。 – peterh
考虑到切换到Roo不是一个真正的解决方案,而是一种解决方法,我想分享我对这个问题的经验。
有你需要检查两件事情:
- 你需要通过AspectJ进行编译的类。 Maven aspectj插件提供了这个要求。
- 实体类必须用
@Configurable
来注释我找到了解决办法:
这是正确的iajc任务
<iajc source ="1.6" target="1.6" sourceroots="src/main/java" destDir="src/main/webapp/WEB-INF/classes" showweaveinfo="true" verbose="true">
<classpath>
<path refid="compile.classpath"/>
<path refid="aspectj.classpath"/>
</classpath>
<aspectpath>
<pathelement location="${workdir}/WEB-INF/lib/spring-aspects-3.2.6.RELEASE.jar" />
</aspectpath>
</iajc>
这里是工作解决方案!我很抱歉,我只能一次支持这一点!谢谢! – peterh
“因为Maven的平时不能做的事等”哈哈哈,你做了我的一天。你知道,成千上万的软件项目一直都在使用maven,所有这些都是世界的颠峰吗?在过去的5年中,我没有在一个单独的项目中工作,而这个项目并不是由Maven构建的。 –
嗨肖恩,任何想法帮助?我的意思是我的网络不好,maven需要从*资源库下载太多的工件。通过使用ant,我可以手动下载它们(使用多线程下载工具),所以速度很快。 –