`
mentien
  • 浏览: 10951 次
  • 性别: Icon_minigender_1
最近访客 更多访客>>
社区版块
存档分类
最新评论

Hibernate4 Struts2 Spring3整合

    博客分类:
  • Java
 
阅读更多
<!--版本采用hibernate-release-4.0.0.CR5  spring3.1.0 RC1  struts-2.2.3.1-->

jdbc.properties 放在src下

<!--JDBC资源配置文件-->
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/webdb
jdbc.username=webdb_admin
jdbc.password=123456


c3p0.acquireIncrement=10
c3p0.initialPoolSize=15
c3p0.minPoolSize=30
c3p0.maxPoolSize=120
c3p0.maxIdleTime=30
c3p0.idleConnectionTestPeriod=30
c3p0.maxStatements=300
c3p0.numHelperThreads=100
c3p0.checkoutTimeout=0
c3p0.validate=true


<!--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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName" default-lazy-init="true">

<!--加载JDBC资源(根据实际情况加载具体的jdbc.properties)-->
<util:properties id="jdbcProperties" location="classpath:jdbc.properties"/>


<!-- 数据源定义,使用c3p0 连接池 -->
<bean id="dataSource"
  class="com.mchange.v2.c3p0.ComboPooledDataSource"
  destroy-method="close">
  <property name="driverClass">
   <value>${jdbc.driverClassName}</value>
  </property>
  <property name="jdbcUrl">
   <value>${jdbc.url}</value>
  </property>
  <property name="user">
   <value>${jdbc.username}</value>
  </property>
  <property name="password">
   <value>${jdbc.password}</value>
  </property>
  <property name="acquireIncrement">
   <value>${c3p0.acquireIncrement}</value>
  </property>
  <property name="initialPoolSize">
   <value>${c3p0.initialPoolSize}</value>
  </property>
  <property name="minPoolSize">
   <value>${c3p0.minPoolSize}</value>
  </property>
  <property name="maxPoolSize">
   <value>${c3p0.maxPoolSize}</value>
  </property>
  <property name="maxIdleTime">
   <value>${c3p0.maxIdleTime}</value>
  </property>
  <property name="idleConnectionTestPeriod">
   <value>${c3p0.idleConnectionTestPeriod}</value>
  </property>
  <property name="maxStatements">
   <value>${c3p0.maxStatements}</value>
  </property>
  <property name="numHelperThreads">
   <value>${c3p0.numHelperThreads}</value>
  </property>
  <property name="checkoutTimeout">
   <value>${c3p0.checkoutTimeout}</value>
  </property>
</bean>


<!--定义SessionFactory 并定义相关实体-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="annotatedClasses">
   <list><!--配实体层,也可定义个文件  把相应实体层放到相应文件中--></list>
  </property>
 
 
  <!--配置Hibernate相关信息-->
  <property name="properties">
   <value>
         hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
         hibernate.show_sql=false
         hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
         hibernate.release_mode=auto
         hibernate.connection.isolation=1
         hibernate.cache.use_query_cache=true
         hibernate.cache.use_second_level_cache=true
         hibernate.jdbc.batch_size=25
         hibernate.jdbc.fetch_size=25
   </value>
  </property>
 
</bean>

<!--Hibernate事务管理(3)-->
<bean id="transactionManager"
  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  <property name="sessionFactory"
   ref="sessionFactory" />
</bean>



<!--配置Spring AOP -->
<tx:advice id="transacAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="get*" read-only="true"/>
   <tx:method name="*list" read-only="true"/>
   <tx:method name="query*" read-only="true"/>
   <tx:method name="*"/>
  </tx:attributes>
</tx:advice>

<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.hanhn"/>

<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>


<context:annotation-config /> 

<aop:config> 
  <aop:pointcut id="executOption" 
   expression="execution(public * com.hanhn.*.*.*(..))" /> 
  <aop:advisor advice-ref="transacAdvice" pointcut-ref="executOption" /> 
</aop:config>

</beans>



<!--Web.xml配置-->

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">
<display-name>webdb</display-name>
<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>


<!--初始化加载applationContext.xml-->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>


<!--配置spring 监听器-->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!--Servlet 2.4+ listener that exposes the request to the current thread, through both LocaleContextHolder and RequestContextHolder-->
<listener>
  <listener-class>
         org.springframework.web.context.request.RequestContextListener
  </listener-class>
</listener>

<!-- Spring 刷新Introspector防止内存泄露  -->
<!-- Listener that flushes the JDK's JavaBeans Introspector cache on web app shutdown  -->
<listener>
  <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>


<!--配置Struts2的过滤器-->

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<!--释放资源-->
<filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>

<filter-mapping>
  <filter-name> struts2 </filter-name>
  <url-pattern>/*</url-pattern>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>



<!--过滤编码-->
<filter>
  <filter-name>EncodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>Encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
</filter>

<!--Servlet 2.3 Filter that binds a Hibernate Session to the thread for the entire processing of the request-->
<filter>
  <filter-name>OpenSessionInViewFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>

</web-app>

jar包地址:http://www.kuaipan.cn/index.php?ac=file&oid=25394217475907681
分享到:
评论
2 楼 lht0211 2012-02-24  
怎么访问数据库的啊?
1 楼 panpan_xin 2012-01-12  
hibernate4哪有这个类org.hibernate.cache.EhCacheProvider 啊?你配置缓存的时候就配置它

相关推荐

    hibernate4struts2spring3整合案例

    本案例聚焦于“Hibernate4、Struts2和Spring3”的整合,这三大框架是Java Web开发中的重要组成部分,分别负责对象关系映射、MVC(模型-视图-控制器)架构和依赖注入。下面我们将详细探讨这些技术以及它们整合的意义...

    最新版本的Struts2+Spring4+Hibernate4框架整合

    整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...

    hibernate struts2 和spring的整合项目

    - 集成Hibernate:通过Spring的SessionFactoryBean配置,将Hibernate与Spring整合,使得数据库操作可以通过Spring的依赖注入来完成。 - 配置Struts2:在struts.xml中定义Action,通过Spring插件实现Action的依赖...

    hibernate,struts2,spring 整合jar包

    SSH整合指的是将Spring、Struts2和Hibernate这三个开源框架集成在一起,用于构建高效、灵活的企业级Java应用。在Java开发中,这三大框架各有其专长:Spring提供了强大的依赖注入和面向切面编程功能,Struts2是MVC...

    struts2 spring hibernate 整合

    【SSH整合】指的是Struts2、Spring和Hibernate这三个开源框架的集成应用,它们在JavaEE企业级开发中占据着重要地位。Struts2是一个MVC框架,负责处理用户请求和控制应用程序流程;Spring是一个全面的后端解决方案,...

    最新项目系统:Struts2+Spring4+Hibernate4三大框架整合

    总的来说,"最新项目系统:Struts2+Spring4+Hibernate4三大框架整合"为学习和实践Java Web开发提供了一个实用的平台,对于提升开发者的技术水平和项目经验具有极大的帮助。通过深入研究和实践,开发者可以掌握Java ...

    struts2 spring hibernate整合的简单登录代码

    Struts2、Spring和Hibernate是Java Web开发中的三大框架,它们各自负责不同的职责:Struts2作为MVC框架处理请求和展示,Spring提供依赖注入和事务管理,Hibernate则作为ORM框架处理数据库操作。将这三个框架整合在...

    struts2 spring hibernate 整合过程

    struts2 spring hibernate 整合过程 希望能对你有帮助,谢谢

    Struts2Spring4Hibernate4整合

    Struts2、Spring4和Hibernate4是Java Web开发中的三大框架,它们的整合是构建高效、灵活的企业级应用的常用方式。在这个SSH(Struts2-Spring-Hibernate)整合的DEMO中,我们主要探讨如何将这三个框架无缝连接,实现...

    最新版Hibernate-struts-spring框架整合.docx

    最新版Hibernate-struts-spring框架整合.docx

    最新版Hibernate-struts-spring框架整合.pdf

    最新版Hibernate-struts-spring框架整合.pdf

    struts2和spring和Hibernate整合的jar包

    Struts2、Spring和Hibernate是Java Web开发中的三大框架,它们各自解决应用程序的不同问题,而将这三者整合在一起可以构建高效、灵活的企业级应用。Struts2作为MVC(Model-View-Controller)框架,负责处理用户请求...

    SSH(struts2,Hibernate,Spring)整合及测试亲测可用

    在整合过程中,开发者需要注意配置文件的正确设置,包括Struts2的struts.xml、Hibernate的hibernate.cfg.xml以及Spring的applicationContext.xml等。还需要确保各框架之间的依赖注入正确无误,例如,Spring需要知道...

    struts2 spring2 hibernate3整合源代码+jar包

    4. **整合Struts2与Hibernate**:通过Spring的Data Access/ORM支持,将SessionFactory注入到DAO中,然后在DAO中通过Session执行数据库操作。 在这个整合的源代码中,`books.sql` 可能是数据库脚本文件,用于创建...

    Struts2 Spring3 Hibernate3.3框架整合

    Struts2 Spring3 Hibernate3.3框架整合,增删改查,包含有数据库建表语句,包含有JAR包,包含有源代码。包含有事务的配置以及运用。使用的是Oracle的序列来提供的主键自增,建表和建立序列的sql语句,已经放在工程...

    struts2+spring+hibernate整合小案例

    Struts2、Spring和Hibernate是Java Web开发中的三大框架,它们的整合应用,通常被称为SSH(Struts2、Spring、Hibernate)集成。这个"struts2+spring+hibernate整合小案例"是一个用于教学和实践的DEMO,旨在帮助...

    Struts2+Spring3+Hibernate4必备整合包

    这里提供的"Struts2+Spring3+Hibernate4必备整合包"是一个集合了这三个框架所需库的压缩文件,方便开发者快速搭建项目环境。 Struts2作为表现层框架,主要负责处理HTTP请求,展示视图,以及控制应用程序的流程。它...

    struts2 spring hibernate 整合架构

    总之,Struts2、Spring和Hibernate的整合为Java Web开发提供了一个强大的工具集,能够处理复杂的业务逻辑,实现松耦合的架构。理解并掌握这三个框架的原理和整合方式,对于提升开发效率和代码质量具有重要意义。

    S2SH整合 struts2 spring4 hibernate4

    在IT行业中,S2SH(Struts2、Spring4、Hibernate4)是一个经典的Java Web开发框架组合,用于构建高效、可扩展的企业级应用。本文将深入探讨这三个组件以及它们的整合过程。 首先,Struts2是Apache软件基金会的一个...

Global site tag (gtag.js) - Google Analytics