0
下面是一個簡單的Web應用程序,配置爲在glassfish4上運行的Rest服務。該應用程序本身工作,可以訪問單個資源。java攔截器不攔截
攔截器不能用於pong(),但魔法般地爲helloW()工作。當我爲helloW()激活時,我可以修改和覆蓋參數,可以拋出異常等等。但是,這對pong()不起作用。在其他地方,我嘗試了無狀態的ejb - 相同的結果 - 不工作 - 即使使用ejb-jar程序集綁定部署描述符。爲什麼?
休息:
package main;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Path("/service")
@javax.ejb.Stateless
public class Service {
@GET
@Produces("text/plain")
// @javax.interceptor.Interceptors({Intercept.class})
public String helloW(String ss){
String msg = pong("QQ");
return msg;
//return ss;
}
@javax.interceptor.Interceptors({Intercept.class})
public String pong(String m){
String temp = m;
return temp;
}
}
攔截器本身:
package main;
@javax.interceptor.Interceptor
public class Intercept {
@javax.interceptor.AroundInvoke
Object qwe(javax.interceptor.InvocationContext ctx) throws Exception{
ctx.setParameters(new Object[]{"intercepted attribute"});
throw new Exception();
// return ctx.proceed();
}
}
是的,我曾嘗試與beans.xml的:
<interceptors><class>main.Intercept</class></interceptors>
沒有喜悅。
謝謝。我想現在應該足夠了。我的參考資料是oracle javaee tutorial和ejb 3第6版。你能推薦別的/更好的嗎? – user2092119
如果你是關於這個問題本身,這是最接近我的參考:https://docs.jboss.org/jbossaop/docs/2.0.0.GA/docs/aspect-framework/reference/en/ HTML/reflection.html。關於其他的參考資料,你可以得到很好的答案:-)。 –