开发者

How to read bean from other xml file (Spring)

I have declared a bean in student.xml file:

<bean id="student1" class="com.raykor.hello.Spring3HelloWorld">
    <property name="name" value="Sachin" />
     <property name="age" value="25" />
    </bean>

and now i want to use it into another file. Is it possible to use beans from ano开发者_如何学运维ther file??


You can import it from another Spring config file, yes, e.g.:

<beans>
    <import resource="config-file-in-same-dir.xml"/>

    <import resource="../config-file-in-parent-dir.xml"/>
</beans>

then you should be able to reference beans defined in your imported config files as if they were defined in that very file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜