0

以下に示すコードのように、requestScope Bean、通常の Java Bean、および Spring 構成があります。Spring で構成された通常の Java コードから Bean のプロパティにアクセスする方法を教えてください。

マネージド Bean

@ManagedBean(name="requestBean")
public class RequestBean {
   private String theID;

   /** getter and setter of theID **/
}

春豆

public class SpringBean {

   private RequestBean theBean = null;

   // how could I access the RequestBean.theID from this class ??
}

春の構成

<bean id="springBean" class="org.huahsin.SpringBean"/>
4

1 に答える 1

0

Maybe I do not understand the question, but I think it is simply by calling the getter:

public class SpringBean {

   private RequestBean theBean = null;

   ...
   public void aCallingMethod() {
      if (theBean != null) {
            theBean.getTheId();  // <-- here it is !!
      }

   }
}

EDIT

To inject the request bean into the Spring bean, either you use an @Autowired annotation:

public class SpringBean {

   @Autowired
   private RequestBean theBean = null;
   ...
}

Either you inject it in your XML file:

<bean id="springBean" class="org.huahsin.SpringBean">
     <property name="theBean" ref="requestBean"/>
</bean>
于 2012-09-29T14:01:54.477 に答える