当前位置:编程学习 > JAVA >>

求教:Spring3 AOP 在Controller里不起作用

请教:
我写了一个demo,直接运行Java的话,aop切面是可以正常执行的。但是我部署到web应用里,aop切面就不起作用了。


package com.test;
@Aspect
@Component
public class SendNotice {

    protected Logger log = Logger.getLogger( getClass() );
    
    
    @Pointcut("execution(* com.test.Test1.testfun(..))")
    public void sendPointcut() {
    }

    @Before("sendPointcut()")
    public void operNotice(JoinPoint point) {
        System.out.println("=========================operNotice");

        
    }

}



package com.test;
@Component("test1")
public class Test1 {

public void testfun(){
System.out.println("=====================testfun()");
}
}




<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop   
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">



    
<context:component-scan base-package="com.test.*"/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<!-- 启动对@AspectJ注解的支持 -->
<aop:aspectj-autoproxy />

     <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>     

</beans>




@Controller
public class TestController {
    @Autowired
    private Test1 test1;

    @RequestMapping("/list.do")
    public String list(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
test1.testfun();
        return null;
    }

public Test1 getTest1() {
return test1;
}
public void setTest1(Test1 test1) {
this.test1 = test1;
}
}


访问TestController 可以执行test1.testfun();这个方法,但是切面不执行。

用的spring3.0
不知道有没有大侠可以帮到我  谢谢


log4j没有任何错误日志 --------------------编程问答-------------------- 大侠,问题解决了吗?我也碰到这样问题了!
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,