SSH整合Spring、Struts、Hibernate、web配置文件

1、Spring配置文件

<!--创建 hiber模板类 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate" autowire="byType">
</bean>

<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.DriverManagerDataSource">
  <property name="user" value="root"></property>
  <property name="password" value=""></property>
  <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
  <property name="jdbcUrl" value="jdbc:mysql://localhost/item?characterEncoding=UTF-8"></property>
</bean>

<!-- 创建Sessio 工厂类 -->
<bean id="sessionfactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" > 
  <property name="configLocation">
     <value>classpath:hibernate.cfg.xml</value>
  </property>
  <property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 创建实物管理对象 -->
<bean id="tx" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionfactory"> </property>
</bean>

<aop:config>
  <aop:pointcut expression="execution(* com.third.service.impl.*.*(..))" id="pointcut"/>
  <aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
</aop:config>

<!-- 创建实物通知 -->
<tx:advice id="advice" transaction-manager="tx">
  <tx:attributes>
    <tx:method name="*"/>
  </tx:attributes>
</tx:advice>
2、Struts配置文件

<?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>

    <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.i18n.encoding" value="UTF-8"/>

    <package name="struts" namespace="/" extends="struts-default">
	<action name=""  class="" method="">
            <result name="success"></result>
        </action>    
    </package>
</struts>
3、Hibernate配置文件
<hibernate-configuration>
 <session-factory name="configlocation">
 <!-- 链接数据库 -->
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost/item?characterEncoding=UTF-8</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
  <!-- 更新数据库 -->
  <property name="hbm2ddl.auto">update</property>
  <!-- 显示sql语句 -->
  <property name="show_sql">true</property>
  <!-- sql语句规范化 -->
  <property name="format_sql">true</property>
 </session-factory>
</hibernate-configuration>
3、web配置文件
 <!-- listener监听 -->
   <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <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>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值