AspectJ 在spring项目中的maven配置

来源:互联网 发布:淘宝女装网店名字 编辑:程序博客网 时间:2024/06/14 10:47
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>me.mritd</groupId>  <artifactId>Test1</artifactId>  <version>1.0-SNAPSHOT</version>  <packaging>jar</packaging>  <dependencies>    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->    <dependency>      <groupId>org.aspectj</groupId>      <artifactId>aspectjrt</artifactId>      <version>1.8.9</version>    </dependency>    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools -->    <dependency>      <groupId>org.aspectj</groupId>      <artifactId>aspectjtools</artifactId>      <version>1.8.9</version>    </dependency>    <dependency>      <groupId>org.aspectj</groupId>      <artifactId>aspectjweaver</artifactId>      <version>1.7.4</version>    </dependency>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>RELEASE</version>    </dependency>    <dependency>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-clean-plugin</artifactId>      <version>2.4.1</version>    </dependency>    <dependency>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-clean-plugin</artifactId>      <version>2.4.1</version>    </dependency>  </dependencies>  <build>    <plugins>      <!-- Maven 编译插件 -->      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-compiler-plugin</artifactId>        <version>3.5.1</version>        <configuration>          <compilerVersion>1.8</compilerVersion>          <fork>true</fork>          <source>1.8</source>          <target>1.8</target>          <encoding>UTF-8</encoding>        </configuration>      </plugin>      <!-- AspectJ 编译插件 -->      <plugin>        <groupId>org.codehaus.mojo</groupId>        <artifactId>aspectj-maven-plugin</artifactId>        <version>1.8</version>        <configuration>          <verbose>true</verbose>          <privateScope>true</privateScope>          <showWeaveInfo>true</showWeaveInfo>          <source>1.8</source>          <target>1.8</target>          <complianceLevel>1.8</complianceLevel>          <!-- <encoding>UTF-8</encoding> -->          <verbose>false</verbose>          <outxml>true</outxml>          <aspectLibraries>            <!-- 此处定义外部的aspect包,例如spring的事务aspect包 。这里引用的包必须在依赖中声明 -->            <!--              <aspectLibrary>                 <groupId>org.springframework</groupId>                 <artifactId>spring-aspects</artifactId>             </aspectLibrary>            -->          </aspectLibraries>        </configuration>        <executions>          <execution>            <goals>              <goal>compile</goal>       <!-- use this goal to weave all your main classes -->              <goal>test-compile</goal>  <!-- use this goal to weave all your test classes -->            </goals>          </execution>        </executions>      </plugin>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-eclipse-plugin</artifactId>        <version>2.6</version>        <configuration>          <ajdtVersion>1.6.11</ajdtVersion>        </configuration>      </plugin>    </plugins>  </build></project>


这个是可以把代码打包成jar 或者war的

注意 我这边用的是idea  idea需要把

File -> settings -> Java Compiler 



这样  

ok

这个大家可以参考下 http://opoo.org/aspectj-compile-time-weaving/


感谢前辈大牛 的分享

1 0
原创粉丝点击