一个Spring简单例子
2010-03-08 08:14
459 查看
HelloBean.java代码如下
beans-config.xml 配制如下
SpringDemo.java代码如下
package onlyfun.caterpillar; public class HelloBean { private String helloWord; public void setHelloWord(String helloWord) { this.helloWord = helloWord; } public String getHelloWord() { return helloWord; } }
beans-config.xml 配制如下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloBean" class="onlyfun.caterpillar.HelloBean"> <property name="helloWord"> <value>Hello!Justin!</value> </property> </bean> </beans>
SpringDemo.java代码如下
package onlyfun.caterpillar; import org.springframework.core.io.FileSystemResource;import org.springframework.core.io.Resource;import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; public class SpringDemo { public static void main(String[] args) { Resource rs = new FileSystemResource("beans-config.xml"); BeanFactory factory = new XmlBeanFactory(rs); HelloBean hello = (HelloBean) factory.getBean("helloBean"); System.out.println(hello.getHelloWord()); } }
相关文章推荐
- spring task 入门 简单的一个例子
- 一个简单的Spring的AOP例子传统方法
- 一个使用spring的最简单的例子。
- 一个简单的Spring.net绑定例子
- 一个简单的Spring的AOP例子
- 一个Spring Boot, JWT,AugularJS接口安全验证的简单例子
- Spring 入门(一个简单的例子)
- Spring 入门(一个简单的例子)--适合初学者
- 一个简单的Spring的AOP例子
- 一个简单的Spring的AOP例子
- 一个简单的Spring的AOP例子
- Spring MVC + Mybatis 一个简单的例子 — 返回Json数据
- Spring 入门(一个简单的例子)
- Spring入门-一个简单的小例子
- Spring入门(一个简单的例子)
- 一个简单的Spring的AOP例子
- SpringMvc+Mybatis+Maven+Mysql做一个CRUD的简单例子
- 一个简单的Spring的AOP例子
- spring集合类型的setter注入的一个简单例子
- 一个简单的Spring的AOP例子