Spring 3.2 Hello World
来源:互联网 发布:刀剑乱舞 知乎 编辑:程序博客网 时间:2024/06/05 11:59
从Spring的官网上下载下来的Framework包,解压后结构如下:
创建HelloWorld我们需要这些包:
注意:com.springsource.org.apache.commons.logging是framework中没有的包,第三方依赖包。
以上就是需要的所有环境,接下来就比较简单了。
套用网上的一点代码(懒得写)
Bean文件: Flower.java
package spring.crazy;public class Flower { private int number; private String name = "rose"; private String color = "red"; public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } }Bean的配置文件: Bean.xml
<?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 id="flower" class="spring.crazy.Flower"></bean> </beans>
测试程序: ShowFlower.java
package spring.crazy;import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; public class ShowFlower { /** * @param args */ public static void main(String[] args) { ApplicationContext context=new FileSystemXmlApplicationContext("src/bean.xml"); Flower flower=context.getBean("flower",Flower.class); System.out.println("Name:"+flower.getName()+" "+"Color:"+flower.getColor()); } }
好啦,我们运行测试程序就可以看到如下结果:
- Spring 3.2 Hello World
- Hello World Spring MVC Hello World
- Spring之Hello World
- spring编写hello world
- Spring之Hello World
- Spring Hello World
- Spring入门hello world
- spring mvc Hello World
- Spring Hello World 实例
- Spring Hello World 实例
- Spring hello world实例
- Spring Hello World 实例
- Spring hello world实例
- Spring MVC hello world!
- Spring hello world实例
- Spring-hello world
- Spring 的Hello world
- spring-boot-hello-world
- 一个30年老程序员的回顾(十)
- Re: What if the CRL distribution points for a CA change?
- UTF-8 GBK UTF8 GB2312 之间的区别和关系
- 正则表达式:安琪拉之歌Aquarian文字查找与翻译
- 设计模式之工厂模式
- Spring 3.2 Hello World
- Java中有关byte和String的转换笔记[转]
- Android中Activity启动模式详解
- Closest node to the target in BST
- Decode Ways
- LLDB中的Python脚本
- Minimum Path Sum
- Search for a Range
- Spiral Matrix