package com.xiaoxin.spring.beans;
public class HelloWorld {
private String name;
public void setName(String name){
this.name = name;
}
public void hello(){
System.out.println("Hello :" + name);
}
}
package com.xiaoxin.spring.beans;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWorld helloworld = (HelloWorld) ctx.getBean("helloworld");
helloworld.hello();
}
}<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--配置Bean -->
<bean id="helloworld" class="com.xiaoxin.spring.beans.HelloWorld">
<property name="name" value="Spring"></property>
</bean>
</beans>
2626

被折叠的 条评论
为什么被折叠?



