Spring Bean reference Example

In Spring, we can access beans i.e reference from the same or different bean configuration file, just have a look in to below scenarios.

scenario 1: if the Bean is in different XML file

If you are trying to access bean from different XML file, then we need to use ‘ref‘ tag with ‘bean‘ attribute.

<ref bean=”beanref”/>
If you see in the below example,”accountDetails” is configured in the Account.xml so we need to use ‘ref‘ tag with ‘bean‘ attribute i.e <ref bean=”accountDetails”/>

 

 scenario 2: if the Bean is in same XML file

 

If you see in the below example,”accountDetails” is configured in the same bean.xml so we need to use ‘ref‘ tag with ‘local‘ attribute i.e

<ref local=”beanref”/>

 

Happy learning Spring Tutorials … :)

 

Posted in Spring and tagged .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">