spring 4 mvc aop 不工作
spring 4 mvc aop not work
pom 像这样
<!-- Spring MVC <spring-framework.version>4.2.2.RELEASE</spring-framework.version> -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- aspectj <aspectj.version>1.8.6</aspectj.version> -->
<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.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
像这样
@Aspect public class RestfulAspect {
@Before("methodPointcut()")
public void beforeImpl() {
System.out.println(" Before Done ");
}
@Pointcut("execution(* com.smart.testspring.Repository.BookRespository.selectAll(..))")
public void methodPointcut() {
System.out.println(" Pointcut ");
}}
像这样的 applicationContext
<aop:aspectj-autoproxy />
<bean id="bookBean" class="com.smart.testspring.Repository.BookRespository" />
<bean id="aspectBean" class="com.smart.testspring.aop.RestfulAspect" />
我尝试 <!--<mvc:annotation-driven />-->
但找不到 controller.so 我没有添加 <mvc:annotation-driven />
.
以上是我的project,但是aspect没有工作,谁帮我看看我的问题
MVC容器是应用子容器,所以AOP配置移到mvc-config配置文件,成功了。
pom 像这样
<!-- Spring MVC <spring-framework.version>4.2.2.RELEASE</spring-framework.version> -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<!-- aspectj <aspectj.version>1.8.6</aspectj.version> -->
<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.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
像这样
@Aspect public class RestfulAspect {
@Before("methodPointcut()")
public void beforeImpl() {
System.out.println(" Before Done ");
}
@Pointcut("execution(* com.smart.testspring.Repository.BookRespository.selectAll(..))")
public void methodPointcut() {
System.out.println(" Pointcut ");
}}
像这样的 applicationContext
<aop:aspectj-autoproxy />
<bean id="bookBean" class="com.smart.testspring.Repository.BookRespository" />
<bean id="aspectBean" class="com.smart.testspring.aop.RestfulAspect" />
我尝试 <!--<mvc:annotation-driven />-->
但找不到 controller.so 我没有添加 <mvc:annotation-driven />
.
以上是我的project,但是aspect没有工作,谁帮我看看我的问题
MVC容器是应用子容器,所以AOP配置移到mvc-config配置文件,成功了。