首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有注入实体管理器: Spring方面JAR是否配置为AJC/AJDT方面库?

没有注入实体管理器: Spring方面JAR是否配置为AJC/AJDT方面库?
EN

Stack Overflow用户
提问于 2012-06-10 02:01:26
回答 3查看 7K关注 0票数 3

我正在尝试编写一个简单的spring rest web服务,因为我不熟悉maven (而且因为maven通常无法完成任务--连接问题),所以我现在尝试ant build。现在,构建正常,服务可以运行了。但如果持久化函数被触发,则会提示:

代码语言:javascript
复制
 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:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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>

任何帮助都将不胜感激。谢谢!

EN

回答 3

Stack Overflow用户

发布于 2014-03-19 21:55:20

我找到了解决方案:

这是正确的iajc任务

代码语言:javascript
复制
<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>
票数 4
EN

Stack Overflow用户

发布于 2012-06-20 10:05:36

通过使用ROO和maven pom解决了此问题。关于如何使用Ant build的信息太少了。

票数 1
EN

Stack Overflow用户

发布于 2013-09-19 06:00:51

考虑到切换到Roo并不是一个真正的解决方案,而是一种变通方法,我想分享一下我在这个问题上的经验。

有两件事你需要检查:

你需要通过编译你的类。Maven aspectj插件提供了必须用@Configurable注释的requirement.

  • Your实体类
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10963310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档