【发布时间】:2013-08-16 07:29:20
【问题描述】:
我使用 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" />
.....
然后我有方面组件 在
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");
}
....
通过这种类型的执行,我假设每个方法都会触发这个切入点。但问题是,这个切入点没有被触发?知道为什么吗?谢谢
仅供参考,我使用 glassfish 4,当我部署我的网络应用程序时,我没有收到任何错误配置。所以我假设我的配置很好。
【问题讨论】:
-
Spring AOP 只建议公共方法。你的建议至少是针对那些触发的,还是根本没有触发?
-
我已经尝试了 loginController 中的公共方法 e.x (@Controller 注释)。我尝试通过jsf页面调用公共方法doLogin() {return string},它仍然没有响应
-
对您的 xml 配置
<context:annotation-config />的小注释已经通过使用<context:component-scan ... />来暗示。 component-scan 的base-package属性可以包含要扫描的包的逗号分隔列表,因此使用 4 个元素代替 4 个元素并在其中放置一个逗号分隔的包列表。为您节省一些 xml。
标签: spring aspectj spring-aop