IDEA2016.3搭建Struts2+Hibernate+Spring項目環境


IDEA搭建SSH環境

1.環境

軟件版本:IntelliJ IDEA 2016.3.2
系統:windows 7 32位 / ubuntu
框架:Hibernate3,Spring3.2, Struts2.3(跟框架版本關系不大)

2.問題

學了java之后又學了SSH三大框架,想做一個整體的項目,卻在怎么搭建SSH環境上耗時不少,照着網上的也一直在報錯,后來才知道配置沒有問題,是XML配置上。現在把整個流程總結一下。

3.解決方法

1.創建Project:.
打開軟件之后:File-->New-->Project。出現下圖,按照下圖設置。
注意:第3步可以選擇下載,我是下載過了,就選了第一個直接導入
完成后點擊Next

2.選擇項目要存放的路徑和項目名稱
然后點擊Finsh

3.創建Tomcat服務
Run-->Edit Configrautions打開如下界面,點左上角的加號,選擇Tomcat Server-->Local

根據下面創建出一個Tomcat Server

首先配置Server界面中的信息:

然后配置Deployment中的信息

4.創建Project Structure
點擊:File-->Project Structure
先看左邊第一個Project

然后是Modules,Modules的中間要選中要操作的項目,右邊先看paths一般是默認,重要的是依賴:Dependencies.在這里點右邊的加號,添加Spring和Hibernate的jar包

再之后是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項目的配置,現在讓這個項目啟動起來:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM