Hello I'm newbie in Spring AOP. I have writed something like this:
My Annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExceptionHandling {
String onSuccess();
String onFailture();
}
Aspect Class:
@Aspect
public class ExceptionHandler implements Serializable {
@Pointcut(value="execution(public * *(..))")
public void anyPublicMethod() {
}
@Around("anyPublicMethod() && @annotation(exceptionHandling)")
public Object displayMessage(ProceedingJoinPoint joinPoint,ExceptionHandling exceptionHandling) throws FileNotFoundException {
try{
Object point = joinPoint.proceed();
new PrintWriter(new File("D:\\log.txt")).append("FUUCK").flush();
FacesMessageProvider.showInfoMessage(
FacesContext.getCurrentInstance(),exceptionHandling.onSuccess());
return point;
} catch(Throwable t) {
new PrintWriter(new File("D:\\log.txt")).append("FUUCK").flush();
FacesMessageProvider.showFatalMessage(
FacesContext.getCurrentInstance(),
exceptionHandling.onFailture());
return null;
}
}
}
Method from ManagedBean
@ExceptionHandling(onSuccess=IMessages.USER_UPDATED,onFailture=IMessages.WRONG_DATA)
public void onClickUpdateFromSession(){
onClickUpdate(sessionManager.getAuthenticatedUserBean());
}
And app-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
">
<aop:aspectj-autoproxy/>
<bean id="exceptionHandler"
class="eteacher.modules.ExceptionHandler"/>
<bean id="sessionManager"
class="eteacher.modules.SessionManager"
scope="session"/>
</beans
I'm trying to make exception handler using Spring AOP and JSF messages but it does not fire the advice. Please help me.