spring - 实体管理器尚未注入(inject):is the Spring Aspects JAR configured as an AJC/AJDT aspects library?

标签 spring aspectj

我正在尝试编写一个简单的 Spring Rest Web 服务,因为我不熟悉 Maven(并且因为 Maven 通常无法完成工作 - 连接问题),所以我现在正在尝试 ant 构建。现在,构建正常,服务可以运行。但如果触发持久化功能,则会提示:

 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)

我的ant 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>

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

最佳答案

我找到了解决方案:

这是正确的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>

关于spring - 实体管理器尚未注入(inject):is the Spring Aspects JAR configured as an AJC/AJDT aspects library?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10963310/

相关文章:

java - Spring MVC 多行表单提交提交新的 ModelAttribute

java - Spring继承不起作用

java - 访问 - 了解用户从哪个国家访问我的应用程序

java - Spring AspectJ loadtimeweaving 未调用

java - 部分编译时用maven编织第三方jar

java - 阅读和理解 AspectJ 切入点?

java - CRUD Repository findById()返回值不同

java - 使用 ClasspathXmlApplicationContext 自定义 Spring ResourceLoader

java - 向类添加类型间公共(public)静态方法

java - Maven 项目中的 AspectJ,无法工作/编织