春天4 mvc aop不行

时间:2015-10-31 02:35:58

标签: spring spring-mvc aop spring-aop

像这样的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 />-->但无法找到控制器。所以我没有添加<mvc:annotation-driven />

以上是我的项目,但方面没有工作,谁帮我查看我的问题。

1 个答案:

答案 0 :(得分:0)

MVC容器是一个应用程序子容器,因此AOP配置被移动到mvc-config配置文件,它可以工作。