【问题标题】:Spring Transaction Management - AspectJ - Compile time loading - SampleSpring 事务管理 - AspectJ - 编译时加载 - 示例
【发布时间】:2018-12-06 23:04:46
【问题描述】:

我想使用aspectj模式在spring boot 2应用程序中实现事务管理。我想使用编译时加载。

谁能提供我的示例代码?

【问题讨论】:

  • 堆栈溢出不是要求人们为您完成工作的地方。在提出问题之前,您应该表明您已经完成了研究,尝试了一些代码并且无法让事情正常工作。你永远不应该要求别人为你做你的工作。你已经做了什么?这个问题已经回答了。你还搜索过吗?您具体需要哪些帮助?你有 RTFM 吗?
  • 请在下面找到我的答案。抱歉,我要求提供代码示例。

标签: spring-boot aspectj


【解决方案1】:

使用 aspectj 的事务管理是通过在编译时或加载时编织事务语义来完成的。 下面的示例是在编译期间完成的。版本没有在下面提到,因为 spring boot 已经管理了它。

如下注释您的持久性配置。我们需要将事务模式设置为方面

@Configuration
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
public class YourPersistenceConfig {
}

Maven 配置

<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
    </dependency>
</dependencies>

<build>    
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.11</version>
            <configuration>
                <sources>
                    <source>
                        <basedir>${project.basedir}</basedir>
                        <includes>
                            <include>**/*.java</include>
                        </includes>
                    </source>
                </sources>      
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
                <source>1.8</source>
                <showWeaveInfo>true</showWeaveInfo>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugin>
</build>

【讨论】:

  • 在日志中为包“org.springframework.transaction”启用跟踪级别。您将能够看到交易的开始和结束。
猜你喜欢
  • 1970-01-01
  • 2011-07-27
  • 2013-03-18
  • 1970-01-01
  • 2019-12-04
  • 1970-01-01
  • 2019-05-10
  • 2015-07-16
相关资源
最近更新 更多