SSH Integration and considerations

Source: Internet
Author: User

Spring Integrated Hibernate configuration

1. Spring Configuration Management DataSource and Sessionfactory

1) Introduce the relevant JDBC configuration file.

<context:property-placeholder location= "Classpath:jdbc.properties"/>

2) configuration DataSource

<bean id= "Datasourceuser" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name= "Driverclass" value= "${user.jdbc.driver}"/>
<property name= "Jdbcurl" value= "${user.jdbc.url}"/>
<property name= "user" value= "${user.jdbc.user}"/>
<property name= "Password" value= "${user.jdbc.password}"/>
<!--The maximum number of connections that are kept in the connection pool. Default value:---
<property name= "maxpoolsize" value= "/>"
<!--the minimum number of connections left in the connection pool, default is:3-->
<property name= "Minpoolsize" value= "2"/>
<!--the number of connections in the connection pool is initialized, the value should be between Minpoolsize and Maxpoolsize, and the default is 3-->
<property name= "Initialpoolsize" value= "2"/>
<!--If False, getting a connection failure will cause all threads that wait for the connection pool to get the connection to throw an exception, but the data source is still valid and continues to try to get the connection the next time it calls Getconnection (). If set to True, the data source will declare broken and permanently shut down after attempting to acquire a connection failure. Default: False-->
<property name= "Breakafteracquirefailure" value= "false"/>

<!--check for idle connections in all connection pools every 60 seconds. Default value: 0, not checked--
<property name= "idleconnectiontestperiod" value= "/>"
<!--c3p0 the size of the global preparedstatements cache. If both maxstatements and maxstatementsperconnection are 0, the cache does not take effect, and if one is not 0, the statement's cache will take effect. If the default value: 0-->
<property name= "maxstatements" value= "/>"
<!--maxstatementsperconnection defines the maximum number of cache statements that a single connection in a connection pool has. Default value: 0--
<property name= "maxstatementsperconnection" value= "0"/>

<!--...-->
</bean>

3) configuration Sessionfactory
<bean id= "Sessionfactory"
class= "Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<!--inject Connection pool--
<property name= "DataSource" ref= "DataSource"/> <!--available by
<!--Configure other properties of Hibernate--
<property name= "Hibernateproperties" >
<props>
<!--<prop key= "Current_session_context_class" >thread</prop><prop key= "Hibernate.dialect" > Org.hibernate.dialect.mysqldialect</prop>--
<prop key= "Hibernate.dialect" >org.shenyundata.cn.base.BlobMySQLDialect</prop>
<prop key= "Hibernate.show_sql" >false</prop>
<prop key= "Hibernate.format_sql" >false</prop>

<!--...-->
</props>
</property>
<!--Configure the annotated entity class for the map---
<property name= "Packagestoscan" >
<list>
<value>org.shenyundata.cn.model</value>
</list>
</property>
</bean>

4. If you use hibernatetemplate, you need the relevant configuration

<bean id= "Hibernatetemplate" class= "Org.springframework.orm.hibernate3.HibernateTemplate" >
<property name= "Sessionfactory" ref= "Sessionfactory" ></property>
</bean>

5. Transaction manager Related Configuration

<bean id= "TransactionManager"
class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory" ></property>
</bean>

6. Facet logical configuration of the transaction manager

<tx:advice id= "Advice" transaction-manager= "TransactionManager" >
<!--configuration Blocker--
<tx:attributes>
<tx:method name= "get*"/>
<tx:method name= "*" rollback-for= "Throwable"/>
</tx:attributes>
</tx:advice>

<!--Configure blocking rules--
<aop:config>
<!--interception rules--
<aop:pointcut id= "Mypointcut"
expression= "Execution (* org.***.cn.service.*.* (..)) or execution (* org.***.cn.task.*.* (..)) "/>
<aop:advisor advice-ref= "Advice" pointcut-ref= "Mypointcut"/>
</aop:config>

Precautions

The 1.spring is responsible for managing service and DAO generation.

The 2.action generation is generated by Struts2 spring's plugin and is not managed by spring.

3. Opensessioninviewfilter Precautions:

1). Must be configured in front of struts2 filter.

2). Filter needs to sessionfactory bean, if need to rename need to add Param-name:sessionfactorybeanname in filter configuration information Param-value

3). If you do not configure transaction, an exception invaliddataaccessapiusageexception write operations is not allowed * * * * * readonly, so remember to configure the transaction manager

7. Related annotation Configuration

<context:annotation-config/>
<!--scanning Package--
<context:component-scan base-package= "com.****"/>

8. If you need to use the ASPECTJ syntax to define the slice class logic, you need the following configuration

<aop:aspectj-autoproxy/> AOP Annotation syntax support, not very important

The AOP XML configuration (important) is shown in 6th.

With related jar packages:

The jar packages for database packages and logs are slightly different depending on the company's situation.

struts.2.1.6 Spring 2.5.6 hibernate3.3.2 Integration

Antlr-2.7.6.jar

Aspectj.jar

Aspectjweaver.jar

Cglib-nodep-2.1.3.jar

Common-annotations.jar

Commons-collections-3.1.jar

Commons-fileupload-1.2.1.jar

Commons-io-1.3.2.jar

Commons-logging-1.1.1.jar

Dom4j-1.6.1.jar

Ejb3-persistence.jar

Freeemarker-2.3.13.jar

Hibernate3.jar

Hibernate-annotations.jar

Hibernate-common-annotations.jar

Javaassist-3.9.0.ga.jar

Jta-1.1.jar

Junit4.5.jar

Mysql Driver Pack

Ognl-2.6.11.jar

Slf4j-api-1.5.8.jar

Slf4j-nop-1.5.8.jar

Spring.jar

Struts2-core-2.1.6.jar

Xwork-2.1.2.jar

Commons-dbcp.jar

Commons-pool.jar

Struts-spring-plugin2.1.6.jar

Personal finishing, if there are errors, welcome to the message to inform, thank you!

SSH Integration and considerations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.