大家好,这个问题困扰我一天多了,在网上也找了很多文章,都没有很好的解决方法。第一类是清除jboss的tmp缓存,第二类自动好的,太奇怪了。以下是我的程序,请高手帮看看,谢谢。环境:采用ejb3.0,服务器用的jboss61.ejb3业务类
@Stateless
@Remote ({Hello2.class})
public class Hello2Bean implements Hello2{
@javax.interceptor.Interceptors({MyIpt.class})
public String hello(String name) {
System.out.println("invoke hello2 method.");
return "hello2," + name;
}
}2.拦截类
public class MyIpt { @javax.interceptor.AroundInvoke
public Object log(InvocationContext ctx) throws Exception {
System.out.println("*** HelloInterceptor intercepting");
long start = System.currentTimeMillis();
try {
if (ctx.getMethod().getName().equals("hello")) {
System.out.println("*** hello 已经被调用! *** ");
}
return ctx.proceed();
} catch (Exception e) {
throw e;
} finally {
long time = System.currentTimeMillis() - start;
System.out.println("用时:" + time + "ms");
}
}
}3.客户端调用类
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "192.168.4.3:1099");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
InitialContext ctx = new InitialContext(props);Hello2 hello2 = (Hello2) ctx.lookup("ejb3demo/Hello2Bean/remote");
System.out.println(hello2.hello("ss"));预期结果,应该是在后台打印:
*** HelloInterceptor intercepting
*** hello 已经被调用! ***但是实际结果是只打印了,ejb业务方法中的"invoke hello2 method.",拦截器没有进入,实在太困惑,请大侠们帮忙看看!
@Stateless
@Remote ({Hello2.class})
public class Hello2Bean implements Hello2{
@javax.interceptor.Interceptors({MyIpt.class})
public String hello(String name) {
System.out.println("invoke hello2 method.");
return "hello2," + name;
}
}2.拦截类
public class MyIpt { @javax.interceptor.AroundInvoke
public Object log(InvocationContext ctx) throws Exception {
System.out.println("*** HelloInterceptor intercepting");
long start = System.currentTimeMillis();
try {
if (ctx.getMethod().getName().equals("hello")) {
System.out.println("*** hello 已经被调用! *** ");
}
return ctx.proceed();
} catch (Exception e) {
throw e;
} finally {
long time = System.currentTimeMillis() - start;
System.out.println("用时:" + time + "ms");
}
}
}3.客户端调用类
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "192.168.4.3:1099");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
InitialContext ctx = new InitialContext(props);Hello2 hello2 = (Hello2) ctx.lookup("ejb3demo/Hello2Bean/remote");
System.out.println(hello2.hello("ss"));预期结果,应该是在后台打印:
*** HelloInterceptor intercepting
*** hello 已经被调用! ***但是实际结果是只打印了,ejb业务方法中的"invoke hello2 method.",拦截器没有进入,实在太困惑,请大侠们帮忙看看!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货