Spring AspectJ通知未执行
我试图在执行操作之前执行日志记录建议,但是调用了该操作,但建议未执行。 我使用的是JSF2.2、Spring3.2和AspectJ-1.6.11 请让我知道我做错了什么,因为它没有给出任何错误,只是建议没有执行 下面是代码示例 LoggingAspect.javaSpring AspectJ通知未执行,spring,jsf,jsf-2,aspectj,jsf-2.2,Spring,Jsf,Jsf 2,Aspectj,Jsf 2.2,我试图在执行操作之前执行日志记录建议,但是调用了该操作,但建议未执行。 我使用的是JSF2.2、Spring3.2和AspectJ-1.6.11 请让我知道我做错了什么,因为它没有给出任何错误,只是建议没有执行 下面是代码示例 LoggingAspect.java package com.igate.mldb.util.aop; import java.util.Arrays; import org.aspectj.lang.JoinPoint; import org.aspectj.lan
package com.igate.mldb.util.aop;
import java.util.Arrays;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LoggingAspect {
@Around("com.example.action.FirstAction.checkLogin()")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable
{
System.out.println("logAround() is running!");
System.out.println("hijacked method : " + joinPoint.getSignature().getName());
System.out.println("hijacked arguments : " + Arrays.toString(joinPoint.getArgs()));
System.out.println("Around before is running!");
joinPoint.proceed(); //continue on the intercepted method
System.out.println("Around after is running!");
System.out.println("******");
}
@Pointcut("execution(public * *(..))")
public void anyPublicOperation() {
System.out.println("Inside Pointcut execution");
}
@Before("execution(public * *(..))")
public void logBefore(JoinPoint joinPoint) {
System.out.println("logBefore() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
}
动作类
FirstAction.java
package com.example.action;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope("request")
public class FirstAction{
private String name;
private String password;
public String checkLogin() {
System.out.println("In Action");
if ((name.equals("mks")) && (password.equals("mks"))) {
System.out.println("In IF");
System.out.println("Name -->" + name + " password-->" + password);
return "SUCCESS";
} else {
System.out.println("In else");
System.out.println("Name -->" + name + " password-->" + password);
return "error";
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
下面是我的spring配置
ApplicationContext.xml
<aop:aspectj-autoproxy />
<context:component-scan base-package="com.example.action, com.igate.mldb" />
JSF配置
faces-config.xml
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>MLDB</base-name>
<var>mldb</var>
</resource-bundle>
</application>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
EN
MLDB
mldb
问候,,
Swapneel Killekar我对Spring知之甚少,但我知道AspectJ语法,可以告诉您,您的
@Around
建议的切入点在方法签名中缺少返回类型。应该是这样的:
大约(“*com.example.action.FirstAction.checkLogin()”)
或者更具体地说,因为checkLogin
返回一个String
:
@Around(“String com.example.action.FirstAction.checkLogin()”)
因此,您的around建议不能返回void
,它还需要返回对象
或字符串
:
@Around(“String com.example.action.FirstAction.checkLogin()”)
公共字符串logAround(ProceedingJoinPoint-joinPoint)抛出可丢弃的
{
System.out.println(“logAround()正在运行!”);
System.out.println(“劫持方法:”+joinPoint.getSignature().getName());
System.out.println(“劫持参数:+Arrays.toString(joinPoint.getArgs()));
System.out.println(“运行前的周围!”);
String result=joinPoint.procedure();//继续执行截获的方法
System.out.println(“运行后的周围!”);
System.out.println(“*******”);
返回结果;
}
我不知道您的Spring配置是否正确,我只能在AspectJ部分提供帮助,对不起。是的,我已经解决了。。。无论如何,谢谢你的回答。