您的位置:首页 > 编程语言 > Java开发

图文教你整合最新版本搭建SSH框架之一:spring(非常详细)

2017-04-08 15:14 686 查看

SSH框架搭建

由于配置过程会使用到很多图片,如果都写在一篇的话,会显得过于冗长,因此搭建过程分为几个博文来写,最终的框架项目我放到整合的那一篇博文中

配置spring

1.首先找到官网,百度输入spring下载搜索即可



2.打开进入网站,找到下图的这个链接



3.点击后进入在网页中搜索Zip Files,找到如图链接



4.进入后即可看到各个版本的spring框架包,选择最新版本



5.选择 dist.zip结尾的文件



6.解压后得到的文件



7.下载完文件包,下面开始进行框架搭建,我个人用的是Eclipse Java EE版本,打开IDE,创建一个Dynamic Web Project(项目名叫SSHDemo),Tomcat根据版本设置,我用的是Tomcat7.0



8.在WEB-INF->lib下新建文件夹spring-framework-4.3.7,从我们刚才的文件包的libs目录下找到如下的jar加入我们Eclipse项目的lib目录下的spring文件夹中



9.然后还需要将这些jar包配置到我们的项目下,具体步骤是右键项目,选择Build Path->Configure Build Path…



10.然后点击Add Jar选择lib目录下的jar加入,最后Apply即可



11.接下来我们在src建立一个包pers.zzf.test,下面建一个SpringTest.java,用来测试Spring框架

package pers.zzf.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class SpringTest {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public static void main(String... args){
ApplicationContext context = new FileSystemXmlApplicationContext("src\\applicationContext.xml");
SpringTest test = (SpringTest) context.getBean("springTest");
System.out.println(test.getName());
}
}


12.由于Spring框架还需要一个配置文件applicationContext.xml,这个模板我们可以到我们之前下载的文件包里面找到spring-framework-reference.pdf这个pdf文件



13.打开这个pdf文件后,搜索XML-based configuration metadata,找到如图的地方可以看到一个配置文件模板



14.在src建一个applicationContext.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="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here -->
</beans>


修改后的模板:

<?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="springTest" class="pers.zzf.test.SpringTest">
<!-- collaborators and configuration for this bean go here -->
<property name="name">
<value>ZZF</value>
</property>
</bean>
<!-- more bean definitions go here -->
</beans>


15.配置到这一步项目结构如下



15.现在可以运行SpringTest.java可以看到控制台输出ZZF
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring hibernate 框架 ssh