0
我一個CDI角色類型裏面包含一些InterceptorBinding爲以下幾點: -的CDI刻板印象不與EJB會話Bean工作
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.METHOD,
ElementType.TYPE})
@Documented
public @interface MyInterceptable {
}
@Interceptor
@MyInterceptable
public class MyInterceptor {
@AroundInvoke
public Object perform(InvocationContext context) throws Exception {
log.info("My Interceptor begin.");
Object result =context.proceed();
log.info("My Interceptor end.");
return result;
}
}
@Stereotype
@MyInterceptable
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.TYPE
})
@Documented
public @interface MyStereoable {
}
當我在非EJB定義這個Sterotype它工作正常。該消息在執行doing1()之前和之後打印。
@Singleton
@MyStereoable
public class MyCustomized {
public void doning1(){
//print something.
}
}
無論如何,當我試圖用無狀態EJB使用它時,它不起作用。攔截器沒有打印任何消息。
@Remote
public interface HelloServiceable extends Serializable {
void doning2();
}
@Stateless
@MyStereoable
public class HelloService implements HelloServiceable {
public void doing2() {
//Print something
}
}
然後我混合殼體1和情形2,如下所示: -
@Stateless
@MyStereoable
public class HelloService implements HelloServiceable {
@Inject
private MyCustomized myBean;
public void doing2() {
this.myBean.doing1();
//Print something
}
}
的MyCustomized可以被截獲並打印該信息,而不是爲無狀態EJB。
我不確定我是否對CDI和EJB有誤解或困惑。你能幫助進一步提供建議嗎?提前感謝您的幫助。我期待儘快收到您的回覆。
Regards,
Charlee Ch。
你在測試什麼容器? – Kris 2011-12-19 13:37:25
我使用Glassfish 3.1.1 for Windows和Weld-1.1.4-Final。請注意,我下載了weld-osgi-bundle-1.1.4.Final.jar並將其替換爲GF_HOME/glassfish/modules。 – 2011-12-20 03:36:55