(一)先搭建Spring
先打开eclipse ,new->project->web选择Dymadic web project新建一个web工程,
我的是neon版本,其他版本选 web Project
这边根据自己的环境选择,我则默认
建好目录如下
然后,我们在/sshDemo/WebContent/WEB-INF/lib/目录下新建一个文件夹spring-framework-4.3.7,用来存放spring的jar包。(没有jar包的可以下载本工程源码:源码下载)
建好后把spring相关jsr包放进来
然后右击工程目录sshDemo->Build Path->configure Build Path 弹出窗口如下
然后选中刚刚spring-framework-4.3.7目录里的jar包,导入jar包
导入成功后,会在src下生成很多小奶瓶,如下图
然后在到src下创建一个springTest文件,来测试spring是否构建成功
springTest文件源码如下:
package test.spring.demo;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class springTest {
private String name;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
public static void main(String[] args) {
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("src\\springBean.xml");
springTest test = (springTest) context.getBean("springTest");
System.out.println(test.getName());
}
}
然后创建spring配置文件springBean.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="springTest" class="test.spring.demo.springTest">
<property name="name">
<value>FXB</value>
</property>
</bean>
</beans>
接下去 就可以到springTest文件测试看看是否spring配置成功。
到这边整个项目目录结构如下
然后开始搭建Hibernate
(二)搭建hibernate