zoukankan      html  css  js  c++  java
  • 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项目的配置,现在让这个项目启动起来:

  • 相关阅读:
    欧几里得算法及扩展欧几里得(含)
    RP
    P1734_最大约数和
    The 2017 ACM-ICPC Asia East Continent League Final记录
    【数据结构】bzoj1651专用牛棚
    【数据结构】bzoj1455罗马游戏
    【数据结构】bzoj1636/bzoj1699排队
    【数据结构】bzoj3747Kinoman
    【计算几何】奇特的门
    Topcoder SRM 608 div1 题解
  • 原文地址:https://www.cnblogs.com/cenyu/p/6297901.html
Copyright © 2011-2022 走看看