Spring @Transactional + AspectJ编译时编织不起作用

问题描述 投票:0回答:1

[我有一堆用@Transactional批注标记的方法,然后它们进行自调用,并且某些方法是私有的,所以我想在Spring中使用AspectJ风格的事务管理。

我正在使用aspectj-maven-plugin 1.11版编译代码:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11</version>
                <configuration>
                    <proc>none</proc>
                    <forceAjcCompile>true</forceAjcCompile>
                    <complianceLevel>${java.version}</complianceLevel>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWeaveInfo>true</showWeaveInfo>


                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>


                    <sources>
                        <source>
                            <basedir>${project.build.directory}/generated-sources/annotations</basedir>
                        </source>
                        <source>
                            <basedir>${project.build.directory}/generated-sources/delombok</basedir>
                        </source>
                    </sources>
                    <testSources>
                        <source>
                            <basedir>
                                ${project.build.directory}/generated-test-sources/delombok
                            </basedir>
                        </source>
                    </testSources>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

编译部分工作正常,我在日志中看到了我的类,并且在类文件中也看到了:一堆...$AjcClosure...类。

但是,我的maven脚本正在使用maven surefire插件执行集成测试(这是春季启动测试),而旨在抛出异常的情况下验证是否正在回滚事务的测试失败了。

这是我的@Configuration文件:

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

// some beans not related to persistence

}

我在这里想念什么?

spring-boot aspectj spring-jdbc spring-transactions compile-time-weaving
1个回答
0
投票

您无需使用AspectJ Maven或任何其他类型的编译时编织工具即可使其在Spring中运行。只需使用AspectJ via LTW (load-time weaving)

© www.soinside.com 2019 - 2024. All rights reserved.