Announcement Announcement Module
Collapse
No announcement yet.
Referencing/Injecting a bean defined in a different config file (newbie) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Referencing/Injecting a bean defined in a different config file (newbie)

    Hi,

    I've got a few applicationContext.xml files in my first web app (eg applicationContext-biz.xml and applicationContext-db.xml), and I've got a newbie questions on referencing beans in different files.

    If I have a business object in applicationContext-biz.xml which needs a Dao object injected that is defined in applicationContext-db.xml I get undefined references and stack traces.

    So (from memory, so disclaimer/etc) in applicationContext-biz.xml I've got:

    <bean id="auditMgr" class="...">
    <property name="auditDao">
    <ref local="auditDao">
    </property>
    </bean>

    And in my applicationContext-db.xml I define auditDao. I know the tests for auditDao are all good, and when I manually do a appCtx.getBean("auditDao") rather than using injection from within my auditMgr life is good, too.

    But how do I inject auditDao from applicationContext-db.xml into auditMgr from applicationContext-biz.xml? Do I somehow need to tell the contextLoader listener that these guys are dependent?

    Any ideas welcome! Thanks heaps,

    Glen.

  • #2
    if you use <ref local="foo"/> then foo has to be defined in the same physical file as the one referencing it. This allows XML tools and editors to verify that local references can be resolved.

    To resolve a reference to a bean anywhere in the context, use <ref bean="foo"/>.

    Have a look through the reference docs for this at http://www.springframework.org/docs/...ns-ref-element

    Comment


    • #3
      Thanks Darren. Works just great!

      Comment

      Working...
      X