How to disable Spring's JpaExceptionTranslatorAspect

烂漫一生 提交于 2019-12-06 05:39:29
Philippe Baye

First, upgrade aspectj-maven-plugin to 1.5 and add the complianceLevel tag in the configuration of the plugin (otherwise it will try to compile with java 1.4 compliance by default). Then you can specify the exclusion through the xmlConfigured property of the aspectj-maven-plugin. This property references a file from your local directory (i.e. where your pom.xml is)

pom.xml exemple :

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <configuration>
      <source>${maven.compiler.source}</source>
      <target>${maven.compiler.target}</target>
      <complianceLevel>${maven.compiler.target}</complianceLevel>
      <xmlConfigured>myCtAspects.xml</xmlConfigured>
      <aspectLibraries>
        <aspectLibrary>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aspects</artifactId>
        </aspectLibrary>
      </aspectLibraries>
      <showWeaveInfo>true</showWeaveInfo>
      <weaveMainSourceFolder>true</weaveMainSourceFolder>
      <proceedOnError>${maven.aspectj.failOnError}</proceedOnError>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>compile</goal>
        </goals>
        <phase>process-resources</phase>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${aspectj.version}</version>
      </dependency>
      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>${aspectj.version}</version>
      </dependency>
    </dependencies>
  </plugin>

Then in myCtAspects.xml file, you just have to specify all the wanted aspects explicitly, including Spring Aspects. In your case:

<?xml version="1.0"?>
<aspectj>
    <aspects>
        <!-- Spring Aspects -->
        <aspect name="org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect"/>
        <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
        <aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>        
        <!-- Your Application Aspects -->
    </aspects>
</aspectj>
Fscellos

Please try to use aop-autoproxy's include proprety with some invert regexp (something like ^((?! JpaExceptionTranslatorAspect).)*$).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!