0

我有一个 requestScope bean、常规 Java bean 和 Spring 配置,就像下面显示的代码一样。我可以知道如何从使用 Spring 配置的常规 Java 代码访问 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

也许我不明白这个问题,但我认为这只是通过调用吸气剂:

public class SpringBean {

   private RequestBean theBean = null;

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

   }
}

编辑

要将请求 bean 注入 Spring bean,您可以使用 @Autowired 注释:

public class SpringBean {

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

要么将其注入 XML 文件:

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