软件版本:IntelliJ IDEA 2016.3.2
系统:windows 7 32位 / ubuntu
框架:Hibernate3,Spring3.2, Struts2.3(跟框架版本关系不大)java
学了java以后又学了SSH三大框架,想作一个总体的项目,却在怎么搭建SSH环境上耗时很多,照着网上的也一直在报错,后来才知道配置没有问题,是XML配置上。如今把整个流程总结一下。web
1.建立Project:.
打开软件以后:File-->New-->Project。出现下图,按照下图设置。
注意:第3步能够选择下载,我是下载过了,就选了第一个直接导入
完成后点击Next
spring
2.选择项目要存放的路径和项目名称
而后点击Finsh
apache
3.建立Tomcat服务
Run-->Edit Configrautions打开以下界面,点左上角的加号,选择Tomcat Server-->Localubuntu
根据下面建立出一个Tomcat Serverwindows
首先配置Server界面中的信息:app
而后配置Deployment中的信息框架
4.建立Project Structure
点击:File-->Project Structure
先看左边第一个Projectssh
而后是Modules,Modules的中间要选中要操做的项目,右边先看paths通常是默认,重要的是依赖:Dependencies.在这里点右边的加号,添加Spring和Hibernate的jar包jsp
再以后是Artifacts,这里是个重点,这一步的做用是把Modules中添加的依赖包放到项目的web/WEB-INF/lib目录下
5.代码部分
jar包都已经引入,Tomcat Server部署也都设置好,还须要在代码都让他们起做用,这部分是必需要写的。须要操做两个文件web.xml中配置Spring,以及建立bean.xml文件
代码是:
web.xml中添加spring配置部分
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
而后在src中建立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"> </beans>
6.以上就用IDEA完成了SSH项目的配置,如今让这个项目启动起来: