3

Here I am writing a spring application, here I want to do is like this:

   <bean id="sqlClient"  class="com.braoda.dao.sqclient.SqlclientWapper">
    <property name="dataSource" ref="dataSource"/>
  </bean>

<bean id="userDao" class="com.braoda.dao.user.UserDaoImpl">
  <property name="sqlSession" ref="***sqlClient.SqlSessionFactoryBean***" />

As the code like, I want use the spring Xml property config from "ref", but "ref" is not a bean but a bean's property. is this illegal in spring or we can not use spring like this.

4

2 に答える 2

3

はい、可能です。

http://forum.spring.io/forum/spring-projects/container/35869-reference-bean-property-within-referenceをご覧ください

次のようなコードを示します <property name="username" value="${local.username}"/>

于 2013-09-17T08:37:44.383 に答える
1

#{...}次の表記法を使用して可能です。

<property name="sqlSessionFactory" value="#{sqlMapClient.getSqlSessionFactory()}"/>

ノート:

  • ${...}Springプロパティ名をその値に置き換えるために使用できます
  • #{...}Springに式を評価させるために使用できます

詳細はhttp://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.htmlを参照してください。

于 2013-10-16T04:54:14.333 に答える