`
gordon20082008
  • 浏览: 25482 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

捣鼓ssh上手的例子-----spring

    博客分类:
  • SSH
阅读更多
HelloBean.java
package onlyfun.caterpillar;

public class HelloBean
{
private String helloWord = "Hello!World!";

public void setHelloWord(String helloWord)
{
this.helloWord = helloWord;
}

public String getHelloWord()
{
return helloWord;
}
}



<?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>


package onlyfun.caterpillar;
import org.springframework.core.io.ClassPathResource;

import java.io.*;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
//XMLBeanFactory 是一个实现了BeanFactory接口的类
public class SpringTest 
{
public static void main(String[] args) throws IOException
{

ClassPathResource resource = new ClassPathResource("bean.xml");
BeanFactory factory = new XmlBeanFactory(resource);

HelloBean hello = (HelloBean) factory.getBean("helloBean"); 
System.out.println(hello.getHelloWord());
}
}




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics