<i id='BoZBh'><tr id='BoZBh'><dt id='BoZBh'><q id='BoZBh'><span id='BoZBh'><b id='BoZBh'><form id='BoZBh'><ins id='BoZBh'></ins><ul id='BoZBh'></ul><sub id='BoZBh'></sub></form><legend id='BoZBh'></legend><bdo id='BoZBh'><pre id='BoZBh'><center id='BoZBh'></center></pre></bdo></b><th id='BoZBh'></th></span></q></dt></tr></i><div id='BoZBh'><tfoot id='BoZBh'></tfoot><dl id='BoZBh'><fieldset id='BoZBh'></fieldset></dl></div>
    • <bdo id='BoZBh'></bdo><ul id='BoZBh'></ul>

    <small id='BoZBh'></small><noframes id='BoZBh'>

        <tfoot id='BoZBh'></tfoot>
        <legend id='BoZBh'><style id='BoZBh'><dir id='BoZBh'><q id='BoZBh'></q></dir></style></legend>
      1. Spring/@Transactional 与 AspectJ 完全被忽略

        Spring / @Transactional with AspectJ is totally ignored(Spring/@Transactional 与 AspectJ 完全被忽略)

        <legend id='9Ixu2'><style id='9Ixu2'><dir id='9Ixu2'><q id='9Ixu2'></q></dir></style></legend>

            <i id='9Ixu2'><tr id='9Ixu2'><dt id='9Ixu2'><q id='9Ixu2'><span id='9Ixu2'><b id='9Ixu2'><form id='9Ixu2'><ins id='9Ixu2'></ins><ul id='9Ixu2'></ul><sub id='9Ixu2'></sub></form><legend id='9Ixu2'></legend><bdo id='9Ixu2'><pre id='9Ixu2'><center id='9Ixu2'></center></pre></bdo></b><th id='9Ixu2'></th></span></q></dt></tr></i><div id='9Ixu2'><tfoot id='9Ixu2'></tfoot><dl id='9Ixu2'><fieldset id='9Ixu2'></fieldset></dl></div>

            <small id='9Ixu2'></small><noframes id='9Ixu2'>

          • <tfoot id='9Ixu2'></tfoot>
              • <bdo id='9Ixu2'></bdo><ul id='9Ixu2'></ul>
                  <tbody id='9Ixu2'></tbody>
                  本文介绍了Spring/@Transactional 与 AspectJ 完全被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用 Spring-Data Neo4j 2.2.0-RELEASE.(我的以下问题适用于任何其他类型的实体映射,为什么不是 JPA)

                  I use Spring-Data Neo4j 2.2.0-RELEASE. (my following issue would be applicable to any other kind of entity mapping, why not JPA)

                  在我的项目中,我有一个使用 @Transactional Spring 注释的公共方法,因为我想更新/保存其中的实体:

                  In my project, I have a public method annotated with @Transactional Spring's annotation, since I want to update/save an entity inside it:

                  public class MeetingServices {
                  
                      private UserRepository userRepository;
                  
                      private MeetingRepository meetingRepository;
                  
                      public void setUserRepository(UserRepository userRepository) {
                          this.userRepository = userRepository;
                      }
                  
                      public void setMeetingRepository(MeetingRepository meetingRepository) {
                          this.meetingRepository = meetingRepository;
                      }
                  
                      @Transactional("neo4jTransactionManager")
                      public void save(Meeting meeting) {
                          User creator = userRepository.getUserByEmail("test@test.com");
                          creator.participateIn(meeting); // this line leads to a NotInTransactionException since it signals that no transaction context is associated.
                          meeting.setCreator(creator);
                      }
                  

                  我的 application-context.xml 如下:

                  My application-context.xml is the following:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <beans xmlns="http://www.springframework.org/schema/beans"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xmlns:context="http://www.springframework.org/schema/context"
                         xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
                         xmlns:tx="http://www.springframework.org/schema/tx"
                         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j
                         http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
                  
                      <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase">
                          <constructor-arg value="target/neo4jgraph" />
                      </bean>
                  
                      <neo4j:config graphDatabaseService="graphDatabaseService" />
                  
                      <bean id="meetingServices" class="services.MeetingServices">
                          <property name="userRepository"><ref bean="userRepository"/></property>
                          <property name="meetingRepository"><ref bean="meetingRepository"/></property>
                      </bean>
                  
                      <bean id="userServices" class="services.UserServices">
                          <property name="userRepository"><ref bean="userRepository"/></property>
                      </bean>
                  
                      <bean id="neo4jTransactionManager"
                          class="org.springframework.transaction.jta.JtaTransactionManager">
                          <property name="transactionManager">
                              <bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
                                  <constructor-arg ref="graphDatabaseService" />
                              </bean>
                          </property>
                          <property name="userTransaction">
                              <bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
                                  <constructor-arg ref="graphDatabaseService" />
                              </bean>
                          </property>
                      </bean>
                  
                      <tx:annotation-driven mode="aspectj"
                          transaction-manager="neo4jTransactionManager" />
                  
                      <!-- auto-generated repositories for Neo4j storage -->
                      <neo4j:repositories base-package="repositories"/> 
                  
                      <context:spring-configured/>
                  
                      <context:annotation-config/>
                  
                  </beans>
                  

                  正如我们在此配置中看到的,aspectJ 用于事务.

                  As we see in this configuration, aspectJ is used for transactions.

                  因此,我尝试通过更改我的 application-context.xml 以使用 proxy 功能而不是 aspectJ 功能来测试另一种方法:

                  So, I tried to test another way of doing by changing my application-context.xml to use the proxy feature instead of aspectJ feature:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <beans xmlns="http://www.springframework.org/schema/beans"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xmlns:context="http://www.springframework.org/schema/context"
                         xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
                         xmlns:tx="http://www.springframework.org/schema/tx"
                         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j
                         http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
                  
                      <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase">
                          <constructor-arg value="target/neo4jgraph" />
                      </bean>
                  
                      <neo4j:config graphDatabaseService="graphDatabaseService" />
                  
                      <bean id="meetingServices" class="services.MeetingServices">
                          <property name="userRepository"><ref bean="userRepository"/></property>
                          <property name="meetingRepository"><ref bean="meetingRepository"/></property>
                      </bean>
                  
                      <bean id="userServices" class="services.UserServices">
                          <property name="userRepository"><ref bean="userRepository"/></property>
                      </bean>
                  
                      <tx:annotation-driven mode="proxy" />
                  
                  
                      <neo4j:repositories base-package="repositories"/>
                  
                      <context:spring-configured/>
                  
                      <context:annotation-config/>
                  
                  </beans>
                  

                  此配置运行良好,因为我的服务方法现在考虑了 @Transactional(其 neo4jTransactionManager 参数当然已删除)注释.

                  This configuration works pretty well since @Transactional (whose neo4jTransactionManager parameter was of course removed) annotation is now taken in account for my service's method.

                  我的问题是,(无论我的项目是否可以使用简单的 proxy 方法):

                  My question is, (no matter whether my project would work with simple proxy method):

                  在我的第一个 Spring 配置中,我遗漏了什么或配置错误导致 aspectJ 事务功能失败?

                  What did I miss or misconfigure in my first Spring's configuration that makes aspectJ transaction features failed?

                  我目前正在使用 Spring 提高我的技术技能,并且阅读了几篇关于 aspectJ 的加载时编织"的文章.这可能与我的问题有关吗?

                  I'm currently improving my technical skills with Spring, and read few articles about "Load-time weaving" for aspectJ. Might this be linked to my issue?

                  推荐答案

                  尝试添加 <context:load-time-weaver/> 以启用加载时间编织并添加 spring-aspects.jar 到类路径.

                  Try adding <context:load-time-weaver/> to enable load time weaving and add the spring-aspects.jar to the classpath.

                  参见 http://static.springsource.org/spring/docs/current/spring-framework-reference/html/aop.html#aop-aj-ltw-spring了解更多信息

                  编辑

                  对于通用java应用程序,即不在web或应用程序容器中运行,您需要通过javaagent选项启用java工具:

                  For generic java applications, ie not running in a web or application container, you need to enable the java instrumentatioin via a javaagent option:

                  java -javaagent:path/to/spring-instrument.jar your.Main
                  

                  如果你想编织你自己的切面,你需要提供一个带有切面声明的 META-INF/aop.xml 文件.(仅 spring 方面不需要,它已在 spring-aspect.jar 中提供).

                  If you want to weaving your own aspects, you need to provide a META-INF/aop.xml file with aspect declarations. (Not requiered for spring only aspects, it's already provided on spring-aspect.jar).

                  最后你可以改用编译时编织,使用maven aspectj插件,例如:

                  Finally you can use compile time weaving instead, using the maven aspectj plugin, for example:

                  <plugin>
                              <groupId>org.codehaus.mojo</groupId>
                              <artifactId>aspectj-maven-plugin</artifactId>
                              <configuration>
                                  <complianceLevel>1.6</complianceLevel>
                                  <aspectLibraries>
                                      <aspectLibrary>
                                          <groupId>org.springframework</groupId>
                                          <artifactId>spring-aspects</artifactId>
                                      </aspectLibrary>
                                  </aspectLibraries>
                              </configuration>
                              <executions>
                                  <execution>
                                      <goals>
                                          <goal>compile</goal>
                                      </goals>
                                  </execution>
                              </executions>
                          </plugin>
                  

                  这篇关于Spring/@Transactional 与 AspectJ 完全被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                      <tbody id='u4z4a'></tbody>

                      <i id='u4z4a'><tr id='u4z4a'><dt id='u4z4a'><q id='u4z4a'><span id='u4z4a'><b id='u4z4a'><form id='u4z4a'><ins id='u4z4a'></ins><ul id='u4z4a'></ul><sub id='u4z4a'></sub></form><legend id='u4z4a'></legend><bdo id='u4z4a'><pre id='u4z4a'><center id='u4z4a'></center></pre></bdo></b><th id='u4z4a'></th></span></q></dt></tr></i><div id='u4z4a'><tfoot id='u4z4a'></tfoot><dl id='u4z4a'><fieldset id='u4z4a'></fieldset></dl></div>

                        <tfoot id='u4z4a'></tfoot>

                          • <bdo id='u4z4a'></bdo><ul id='u4z4a'></ul>

                            <small id='u4z4a'></small><noframes id='u4z4a'>

                            <legend id='u4z4a'><style id='u4z4a'><dir id='u4z4a'><q id='u4z4a'></q></dir></style></legend>