这一节就改引入spring了,配置什么的就不说了。
配置文件主要内容,注意此处注入对象,都是构造器注入。
<bean name="fileHelloWorld" class="com.michael.spring.FileHelloWorld">
<constructor-arg>
<value>helloworld.properties</value>
</constructor-arg>
</bean>
<bean name="helloworldstr" class="com.michael.spring.HelloWorldStr">
<constructor-arg>
<ref bean="fileHelloWorld" />
</constructor-arg>
</bean>
---------------------------------------------------------------------------------------------------------------------------
根据java反射机制 加载
--------------------------------------------------------------------------------------------------------------------------
/**
* @ClassName: HelloWorldClient
* @Description: TODO(客户端调用)
* @author huangbin 876301469@qq.com
* @date 2014-4-2 下午8:48:28
*
*/
public class HelloWorldClient {
public static void main(String[] args) {
Resource resource = new ClassPathResource("spring.xml");
BeanFactory factory = new XmlBeanFactory(resource);
HelloWorldStr hello = (HelloWorldStr) factory.getBean("helloworldstr");
System.out.println(hello.getContent());
}