SSH基础配置

来源:互联网 发布:vs2015配置unity3d 编辑:程序博客网 时间:2024/06/08 13:32

application+hibernate.xml
使用的c3p0连接池

<?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.xsd    http://www.springframework.org/schema/context    http://www.springframework.org/schema/context/spring-context.xsd    http://www.springframework.org/schema/aop    http://www.springframework.org/schema/aop/spring-aop.xsd    http://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="com.mysql.jdbc.Driver"/>        <property name="jdbcUrl" value="jdbc:mysql:///spring_day04"/>        <property name="user" value="root"/>        <property name="password" value=""/>    </bean>    <!--编写bean,名称是固定的,加载hibernate.cfg.xml配置文件-->    <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>com/itheima/domain/Customer.hbm.xml</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"/>    <!--配置客户模块-->    <!--强调:以后配置Action,必须是多例的-->    <bean id="customerAction" class="com.itheima.web.action.CustomerAction" scope="prototype">        <property name="customerService" ref="customerService"/>    </bean>    <bean id="customerService" class="com.itheima.service.CustomerServiceImpl">        <property name="customerDao" ref="customerDao"/>    </bean>    <bean id="customerDao" class="com.itheima.dao.CustomerDaoImpl">        <property name="sessionFactory" ref="sessionFactory"/>    </bean></beans>

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="crm" extends="struts-default" namespace="/">        <!--配置客户的Action,如果Action由Spring框架来管理,class标签上只需要编写ID值就OK-->        <action name="customer_*" class="customerAction" method="{1}">        <!--<action name="customer_*" class="com.itheima.web.action.CustomerAction" method="{1}">-->        </action>    </package></struts>

web.xml

<?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">    <!--配置spring整合WEB的监听器-->    <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>    <!--解决延迟加载问题-->    <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></web-app>