首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xml配备格式加载

2012-08-17 
xml配置格式加载?package com.ls.spring.ioc.dummyimport org.springframework.stereotype.Component@Co

xml配置格式加载

?

package com.ls.spring.ioc.dummy;import org.springframework.stereotype.Component;@Componentpublic class B {public void put() {System.out.println("B is outing...");}}package com.ls.spring.ioc.dummy;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;@Componentpublic class A {@Autowiredprivate B b;public A() {super();}public A(B b) {super();this.b = b;}public B getB() {return b;}public void setB(B b) {this.b = b;}}
?

<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
??? <bean id="a" >
??? ??? <constructor-arg index="0">
??? ??? ??? <ref bean="b"/>
??? ??? </constructor-arg>
??? </bean>
??? <bean id="b" />
</beans>

?

package com.ls.spring.ioc.dummy;import org.springframework.beans.factory.support.DefaultListableBeanFactory;import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;public class TestBeanFactoryViaXml {public static void main(String[] args) {DefaultListableBeanFactory factory = new DefaultListableBeanFactory();XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);reader.loadBeanDefinitions("classpath:com/ls/spring/ioc/dummy/ioc-test.xml");A a = (A) factory.getBean("a");a.getB().put();}}
?

?

?

?

?

?

热点排行