Spring环境搭建和示例工程
来源:互联网 发布:吃鸡为什么不优化 编辑:程序博客网 时间:2024/06/06 04:04
/**
* spring官网:https://spring.io/
下载地址http://projects.spring.io/spring-framework/
Spring Framework下的Reference
2.3. Usage scenarios
点击Distribution Zip Files
Distribution Zip Files
真实下载地址 http://repo.spring.io/release/org/springframework/spring
点击一个版本
然后点击最上层的第一个:spring-framework-4.3.3.RELEASE-dist.zip 解压
* 第一步:新建一个普通java工程new-other-java Project
第二步:建立lib文件夹,引入spring-framework的jar文件全部拷贝到工程中
javadoc和sources 结尾的不用拷贝
最主要的有:spring-aop、spring-beans、spring-context、spring-core
第三步:添加到buildPath:右键点击工程名称-Properties-Java Build Path-Add JARs…
下载Apache Commons Logging
http://commons.apache.org/proper/commons-logging/download_logging.cgi
commons-logging-1.2.jar也同上添加进去/
*/
IHelloMessage.java接口文件:
package com.jike.spring.chapter01;
public interface IHelloMessage{
publicString sayHello();
}
HelloChina.java文件:
package com.jike.spring.chapter01;
public classHelloChina implementsIHelloMessage {
@Override
publicString sayHello(){
// TODO Auto-generated method stub
return"大家好!";
}
}
HelloWorld.java文件:
package com.jike.spring.chapter01;
public classHelloWorld implementsIHelloMessage {
@Override
publicString sayHello(){
// TODO Auto-generated method stub
return"Hello World!";
}
}
Person.java文件:
package com.jike.spring.chapter01;
public class Person{
private IHelloMessage helloMessage;
publicIHelloMessage getHelloMessage(){
return helloMessage;
}
publicvoid setHelloMessage(IHelloMessagehelloMessage){
this.helloMessage= helloMessage;
}
publicString sayHello(){
return this.helloMessage.sayHello();
}
}
helloMessage.xml文件:
<?xml version="1.0"encoding="UTF-8"?>
<!DOCTYPE beansPUBLIC "-//SPRING/DTD BEAN/EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloWorld" class="com.jike.spring.chapter01.HelloWorld"></bean>
<bean id="helloChina" class="com.jike.spring.chapter01.HelloChina"></bean>
<bean id="person" class="com.jike.spring.chapter01.Person">
<propertyname="helloMessage" ref="helloChina"/>
</bean>
</beans>
Main.java文件:
package com.jike.spring.chapter01;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
public class Main{
//2.Spring 入门示例----03创建示例工程
public staticvoid main(String[]args) {
//加载配置文件 以及启动IOC容器 调用人物类 向用户输出问候信息
Resource r = new FileSystemResource("helloMessage.xml");
BeanFactory f= newXmlBeanFactory(r);
Person person= (Person)f.getBean("person");
String s = person.sayHello();
System.out.print("The person is currently saying:"+ s);
}
}
//Main.java右键RunAs--java Application
- Spring环境搭建和示例工程
- Spring开发环境搭建以及创建示例工程
- Spring开发环境搭建和第一个示例程序
- simple-spring-memcached maven工程环境搭建
- SpringMVC+Spring搭建web工程环境
- Robolectric环境搭建——运行RobolectricSample示例工程
- Spring Quartz Java工程版和Web工程版示例
- Spring Quartz Java工程版和Web工程版示例
- Spring初识和环境搭建
- activiti工程环境搭建和流程图创建
- activiti工程环境搭建和流程图创建
- activiti工程环境搭建和流程图创建
- MongoDB环境搭建和简单示例
- Android ndk 开发环境搭建 和 示例
- iBatis开发环境搭建和示例
- NDK环境搭建和JNI示例详解
- spring+webservice工程示例
- Spring示例工程
- ceph集成测试调研
- 操作系统发展史
- HBase Rowkey的散列与预分区设计
- Collaborative Deep Learning for Recommender Systems
- hdu5584LCM Walk+gcd
- Spring环境搭建和示例工程
- 多层感知器 by Theano
- 《java编程思想》第十六章 数组
- 客户机服务器模式(C/S模式)
- 狂热的数学建模爱好者
- 网络编程入门服务器端程序
- os和sys
- Hello,C!
- 请不要重复犯我在学习Python和Linux系统上的错误