以下对我有用:
aop.xml
在目录下创建一个名为:的文件META-INF
(与persistence.xml
.
修改以在您的bean 定义webApplicationContext.xml
中包含 Spring 方面 bean (在主项目中)。 emf
src/java/resources
在aspectj-maven-plugin
您的pom.xml
.
确保告诉 aspectj 插件您要编译 Java 7 代码,否则它将尝试使用默认的 AspectJ-1.6 编织器来编织您的 1.7 代码。
1 - aop.xml
<!DOCTYPE aspectj PUBLIC
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="com.example.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.example.aspect.NullifyNoResultExceptionAspect"/>
</aspects>
</aspectj>
2 - WebApplicationContext.xml
你的 emf bean 应该是这样的:
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="za.org.serviceseta.model" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${hibernate.showsql}" />
<property name="generateDdl" value="${jpa.generateDdl}" />
<property name="databasePlatform"
value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
_注意,有些教程告诉你包含<context:load-time-weaver />
,但这仅适用于toplink,不适用于spring;春想见豆。
3 - pom.xml - 第 1 部分:告诉jetty-maven-plugin
使用 spring javaagent
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.0.M5</version>
<configuration>
<forkMode>once</forkMode>
<argLine>
-javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.framework.version}/spring-instrument-${spring.framework.version}.jar"
</argLine>
....
3 - pom.xml - 第 2 部分:aspectj-maven-plugin
<project>
....
<properties>
<aspectj.version>1.7.2</aspectj.version>
<!-- note that AspectJ warns you that it prefers 1.6.11, but this works -->
.....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source> <!-- need these for Java 7! -->
<target>1.7</target> <!-- need these for Java 7! -->
<Xlint>ignore</Xlint>
<complianceLevel>1.7</complianceLevel> <!-- need these for Java 7! -->
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</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>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>
</dependencies>
</plugin>
3 - pom.xml 第 3 部分:依赖项
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-agent</artifactId>
<version>2.5.6</version>
</dependency>
如果我遗漏了什么,请随时发表评论。