请教:
我写了一个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没有任何错误日志
我写了一个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没有任何错误日志
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货