我无法通过ASpectj拦截JSF托管bean方法。 你知道如何使它成为可能吗?我的意思是,spring只拦截自己的上下文类方法吗?
Aspect Class
package com.netas.afad.log;
import java.util.Arrays;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import com.netas.afad.log.annotation.DBOperation;
import com.netas.afad.log.annotation.GuiOperation;
@Aspect
public class LogMonitor {
int count;
@Around(value = "@annotation(guiOperation)")
public Object LogGUIOperation(final ProceedingJoinPoint joinPoint, final GuiOperation guiOperation) throws Throwable {
count++;
final long startMillis = System.currentTimeMillis();
try {
System.out.println("Starting GUI operation");
final Object retVal = joinPoint.proceed();
return retVal;
} finally {
final long duration = System.currentTimeMillis() - startMillis;
System.out.println("GUI" + joinPoint.getSignature() + " took " + duration + " ms"+ "count:"+count+ " threadId:"+ Thread.currentThread().getId());
//System.out.println("count:"+count+ " threadId:"+ Thread.currentThread().getId());
}
}
@Around(value = "@annotation(dbOperation)")
public Object LogDBOperation(final ProceedingJoinPoint joinPoint, final DBOperation dbOperation) throws Throwable {
count++;
final long startMillis = System.currentTimeMillis();
try {
System.out.println("Starting DB operation");
final Object retVal = joinPoint.proceed();
return retVal;
} finally {
final long duration = System.currentTimeMillis() - startMillis;
System.out.println("DB Completed. Call to " + joinPoint.getSignature() + " took " + duration + " ms"+ "count:"+count+ " threadId:"+ Thread.currentThread().getId());
//System.out.println("count:"+count+ " threadId:"+ Thread.currentThread().getId());
}
}
}
LoginBean.java
package com.netas.afad.bean;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.netas.afad.log.annotation.GuiOperation;
import com.netas.afad.service.UserService;
@Component
@Scope("request")
public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
@Autowired
UserService userService;
private long id;
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@GuiOperation(name="TESTGUIOP")
public void yetkiGuncelle(){
userService.yetkiGuncelle(id, 5);
}
}
package com.netas.afad.log.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention (RetentionPolicy.RUNTIME)
public @interface GuiOperation {
String name();
}
Spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:int-security="http://www.springframework.org/schema/integration/security"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="http://www.springframework.org/schema/integration/security
http://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/faces
http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
<context:component-scan base-package="com.netas.afad" />
<aop:aspectj-autoproxy />
<bean id="performanceLogger" class="com.netas.afad.log.LogMonitor" />
</beans>