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。关于其他的参考资料,你可以得到很好的答案:-)。 –