eth*_*b_0 2 jsf interceptor cdi jsf-2 managed-bean
我是JSF-2和CDI的新手(我来自Spring世界).
我想从@ManagedBean拦截一个方法,但我的Interceptor类永远不会被调用.有可能吗?
LogInterceptor.java
@Interceptor
public class LogInterceptor {
@AroundInvoke
public Object log(InvocationContext ctx) throws Exception {
System.out.println("begin method interceptor");
Object methodReturn = ctx.proceed();
System.out.println("end method interceptor");
return methodReturn;
}
}
Run Code Online (Sandbox Code Playgroud)
RoleMB
@ManagedBean
@ViewScoped
public class RoleMB extends BaseMB {
@Interceptors(LogInterceptor.class)
public void preEditRole(Role role) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
beans.xml中
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>br.com.preventsenior.services.log.LogInterceptor</class>
</interceptors>
</beans>
Run Code Online (Sandbox Code Playgroud)
将log(InvocationContext ctx)
永远不会被调用.
Java EE拦截器仅适用于CDI托管bean和EJB,而不适用于JSF托管bean.
所以,你基本上有两个选择:
通过CDI bean管理注释更改JSF bean管理注释(@Named
et.al.)
拦截EJB方法,而JSE托管bean又调用它.在一个理智的Java EE应用程序中,真正的业务逻辑无论如何都属于EJB.
归档时间: |
|
查看次数: |
2860 次 |
最近记录: |