struts2+spring+hibernate整合配置

struts2+spring+hibernate 配置:

1、web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<!-- 定义Struts2的FilterDispathcer的Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 用于初始化Spring容器的Listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>


2、applicationContext.xml

<?xml version="1.0" encoding="GBK"?>
<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">

<!-- 定义数据源Bean,使用C3P0数据源实现 -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<!--指定连接数据库的驱动-->
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<!--指定连接数据库的URL -->
<property name="jdbcUrl">
<value>jdbc:mysql://127.0.0.1:3306/databaseName</value>
</property>
<!--指定连接数据库的用户名 -->
<property name="user" value="******" />
<!--指定连接数据库的密码 -->
<property name="password" value="******" />
<!--指定连接池的最大连接数 -->
<property name="maxPoolSize" value="2" />
<!--指定连接池的最小连接数 -->
<property name="minPoolSize" value="1" />
<!--指定连接池的初始化连接数 -->
<property name="initialPoolSize" value="1" />
<!--指定连接数据库连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="10" />
</bean>

<!--定义了Hibernate的SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation"
value="classpath:hibernate.cfg.xml" />
</bean>

<bean id="baseDAO" class="com.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="userService" class="com.service.impl.UserService">
<property name="dao" ref="baseDAO"></property>
</bean>
<!--其他service bean省略-->
</beans>


下面是接上文上传的jar文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值