SSH框架环境搭建

来源:互联网 发布:中立数据 编辑:程序博客网 时间:2024/05/18 00:03

ssh就是Struts2、Spring、Hibernate。

ssh环境搭建:

一、导入相关jar包

二、创建相关配置文件

/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  <display-name>crm_28</display-name>  <!--                配置Spring框架整合WEB的监听器 ,监听servletContext的创建,在启动web容器时自动装配ApplicationContext.xml               配置信息,只加载一次,如果不配置,ApplicationContext.xml会加载多次,效率低  --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!--           解决延迟加载的问题,用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。    Open Session In View在request把session绑定到当前thread期间一直保持hibernate session在open状态,          使session在request的整个期间都可以使用 --><filter><filter-name>OpenSessionInViewFilter</filter-name><filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>OpenSessionInViewFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- 配置Struts2框架的核心的过滤器 --><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>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list></web-app>

src/Struts.xml

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><!-- 先配置包结构 --><package name="" extends="struts-default" namespace="/"><action name="" class="" method="{1}"></action></package>    </struts>

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"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 先配置C3P0的连接池 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value=""/><property name="jdbcUrl" value=""/><property name="user" value=""/><property name="password" value=""/></bean><!-- LocalSessionFactoryBean加载配置文件 --><bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"><!-- 先加载连接池 --><property name="dataSource" ref="dataSource"/><!-- 加载方言,加载可选 --><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><!-- 引入映射的配置文件 --><property name="mappingResources"><list><value></value></list></property></bean><!-- 先配置平台事务管理器 --><bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"/></bean><!-- 开启事务的注解 --><tx:annotation-driven transaction-manager="transactionManager"/><!-- 配置功能模块 --></beans>


三、编码



原创粉丝点击