Java反射不会修改我的@Named bean变量

| 我知道不应该使用反射,但这是一个临时解决方案,直到... 我有1:
@Named(\"PoiBean\")
@SessionScoped
public class PoiBean implements ActionContext, Serializable {
   private String name = \"www\";

   @EJB
   private NavigationServiceRemote nav;

@PostConstruct
private void testReflection() {
    try {
        nav.TestMe(this);
    } catch (NoSuchMethodException ex) {
        Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalArgumentException ex) {
        Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(PoiBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void prepareListAllForm() {
    this.setName(\"test me\");
    }
}
我有2个:
@Stateless(mappedName=\"NavigationService\")
public class NavigationServiceBean implements NavigationServiceRemote, NavigationContext {
    @Override
     public void TestMe(ActionContext ctx) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { 

        Method method = ctx.getClass().getMethod(\"prepareListAllForm\", new Class[] {});
        method.invoke(ctx, new Object[] {});
      }
说明:当PoiBean启动时,将注入EJB nav,然后在@PostConstruct中调用测试方法TestMe。 当我调试时,在PoiBean :: prepareListAllForm(通过反射调用)中,在Test me name = www之前,将名称变量修改为\“ test me \”,然后在返回名称后返回www。 就像反射对PoiBean的副本调用prepareListAllForm一样... 我现在想要实现的是使用prepareListAllForm函数修改该变量,该函数使用来自@EJB的反射来调用。     
已邀请:
NavigationServiceRemote是否带有@Remote注释? EJB接口的远程调用将封送/取消封送参数并返回值,因此TestMe方法将收到PoiBean的副本。如果要修改实例,则需要使用本地EJB。     

要回复问题请先登录注册