我仔细阅读了有关的文章拦截器 http://docs.jboss.org/weld/reference/1.0.0/en-US/html/interceptors.html在接缝/焊接文档中并实施了InterceptorBinding
:
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface MyLog {}
and a Interceptor
class:
@MyLog @Interceptor
public class ErpLogInterceptor implements Serializable
{
@AroundInvoke
public Object logMethodEntry(InvocationContext invocationContext) throws Exception
{..}
@PostConstruct
public Object logPostConstruct(InvocationContext invocationContext) throws Exception
{...}
}
不,我尝试激活拦截器@Named @ViewScoped
bean:
@javax.inject.Named;
@javax.faces.bean.ViewScoped
public class MyBean implements Serializable
{
@PostConstruct @MyLog
public void init()
{...}
@MyLog public void toggleButton()
{..}
}
如果我按下 JSF 页面上的按钮,该方法toggleButton
被正确调用and拦截器方法logMethodEntry
叫做。不过好像方法@PostConstruct
(我感兴趣的)从来没有被我的班级拦截过。
这个问题似乎与Java EE 拦截器和 @ViewScoped bean https://stackoverflow.com/questions/12841351但实际上我的拦截器正在工作normal方法。
您应该设置返回类型@PostConstruct
拦截器void
not Object
。
改变:
@PostConstruct
public Object logPostConstruct(InvocationContext invocationContext) throws Exception
{...}
to:
@PostConstruct
public void logPostConstruct(InvocationContext invocationContext) throws Exception
{...}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)