Ald*_*ndi 2 spring aspectj spring-aop
我使用JSF 2.2 + Spring框架3.2.4
所以,我有这个applicationContent.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config/>
<context:component-scan base-package="com.vulcan.controller" />
<context:component-scan base-package="com.vulcan.service" />
<context:component-scan base-package="com.vulcan.dao" />
<context:component-scan base-package="com.vulcan.spring.aop" />
.....
Run Code Online (Sandbox Code Playgroud)
然后我有方面组件
package com.vulcan.spring.aop;
@Aspect
public class LoggingService {
private Log log = LogFactory.getLog(this.getClass());
@Pointcut("execution(* *.*(..))")
protected void loggingOperation() {}
@Before("loggingOperation()")
public void logJoinPoint()
{
System.out.println ("Hello");
}
....
Run Code Online (Sandbox Code Playgroud)
通过这种类型的执行,我假设将在每个方法上触发此切入点.但问题是,这个切入点没有被触发?知道为什么吗?谢谢
仅供参考,我使用glassfish 4,当我部署我的网络应用程序时,我没有收到任何错误配置.所以我认为我的配置很好.
M. *_*num 15
@AspectSpring没有自动检测到注释类,因为没有检测到它,所以<aop:aspectj-autoproxy />bean 不知道.所以基本上没有方面.
添加@Component到带@Aspect注释的类中,以便Spring可以检测并使用该方面.
@Compopnent
@Aspect
public class LoggingService { ... }
Run Code Online (Sandbox Code Playgroud)
或者在xml文件中明确声明方面
<bean class="LoggingService" />
Run Code Online (Sandbox Code Playgroud)
无论哪种方式,<aop:aspectj-autoproxy />bean 都会获取方面,并且会运行建议.
| 归档时间: |
|
| 查看次数: |
7674 次 |
| 最近记录: |