Spring bean在相同xml文件和不同的xml文件中引用的方式
来源:互联网 发布:java怎么输入字符串 编辑:程序博客网 时间:2024/06/05 04:28
Bean在相同的xml文件中,可以通过ref便签,以及它的local属性来引用它。如下所示:
<beans
xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:p="http://www.springframework.org/schema/p";
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsd";
<bean id="StudentBean" class="com.spenglu.Student">
<property name="teacher" >
<ref local="helloBean"/>
</property>
</bean>
<bean id="helloBean" class="com.spenglu.Teacher">
</bean>
</beans>
Bean在不同的xml文件中,可以通过ref标签的bean属性来引用它。如下所示:
Student.xml:
<beans
xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:p="http://www.springframework.org/schema/p";
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsd";
<bean id="StudentBean" class="com.spenglu.Student">
<property name="teacher" >
<ref bean="helloBean"/>
</property>
</bean>
</beans>
Teacher.xml:
<beans
xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:p="http://www.springframework.org/schema/p";
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsd";
<bean id="helloBean" class="com.spenglu.Teacher">
</bean>
</beans>
阅读全文
0 0
- Spring bean在相同xml文件和不同的xml文件中引用的方式
- Spring在xml文件中配置bean
- Spring在xml文件中配置bean
- Spring中引用不同xml中的bean
- spring中配置Bean的xml方式和注解方式
- ssh项目中,对于spring的bean.xml和web.xml文件的基本配置
- Spring基础——在 Spring Config 文件中基于 XML 的 Bean 的自动装配
- spring引用不同的xml配置文件中的bean
- 如何在web.xml中引用其它的xml文件
- spring引用另一xml文件中的bean
- spring引用另一xml文件中的bean
- Spring 3.0 中bean.xml文件的配置问题
- Spring:传统的XML文件装配Bean
- 在Maven项目中加载spring中的bean的配置xml文件会提示找不到解决方法
- Spring框架中读取xml文件的两种不同方式
- 在applicationContext.xml文件中配置SessionFactory和dataSource的bean
- 在xml中如何引用自己定义的schema文件?
- Spring中加载ApplicationContext.xml文件的方式
- 使用PDFKit写一个基本的PDF阅读器
- 原来Github上的README.md文件这么有意思——Markdown语言详解
- 索引概念
- 粒子系统学习(1)
- eclipse中复制web项目
- Spring bean在相同xml文件和不同的xml文件中引用的方式
- 优化图片的小尝试
- Java 学习-对象
- java类重写equals和hashCode方法
- mysql根据条件做特定的更新
- 文本相似度-词袋模型
- Sublime Text 3 快捷键总结
- 布局
- struts2 搭建环境后出现 no action mapped for namespace 的解决方法