读书人

spring跟hibernate集成基于注解的配

发布时间: 2012-12-21 12:03:49 作者: rapoo

spring和hibernate集成,基于注解的配置

<?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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"><context:component-scan base-package="com.zyn"></context:component-scan><!-- 定义受环境影响易变的变量 --><beanvalue="SYSTEM_PROPERTIES_MODE_OVERRIDE" /><property name="ignoreResourceNotFound" value="true" /><property name="locations"><list><!-- 本地开发环境配置 --><value>classpath*:/application.local.properties</value><!-- 集群中节点配置 --><value>classpath*:/application.cluster.properties</value><!-- 标准配置 --><value>classpath*:/application.properties</value><!-- 服务器生产环境配置 --><!-- <value>file:/var/myapp/application.server.properties</value> --></list></property></bean><!-- c3p0 --><bean id="dataSource" value="${jdbc.driver}"></property><property name="jdbcUrl" value="${jdbc.url}"></property><property name="user" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean><!-- <bean id="dataSource" value="${jdbc.driver}"> </property> <property name="url" value="${jdbc.url}"> </property> <property name="username" value="${jdbc.username}"> </property> <property name="password" value="${jdbc.password}"> </property> </bean> --><bean id="sessionFactory"ref="dataSource" /><property name="hibernateProperties"><props><prop key="hibernate.dialect">${hibernate.dialect}</prop><prop key="hibernate.show_sql">${hibernate.show_sql}</prop><prop key="current_session_context_class">thread</prop><prop key="hibernate.hbm2ddl.auto">${hibernate.auto}</prop><prop key="hibernate.connection.provider_class">{hibernate.connection.provider_class}</prop><prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</prop><prop key="hibernate.search.default.indexBase">F:/temp/index</prop></props></property><property name="annotatedClasses"><list><value>com.zyn.ssh.pojo.Student</value></list></property></bean><!-- 事务管理器配置,单数据源事务 --><bean id="transactionManager"ref="sessionFactory" /></bean><!-- 使用annotation定义事务 --><tx:annotation-driven transaction-manager="transactionManager"proxy-target-/></beans>
?application.properties
jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/zyn?useUnicode=true&characterEncoding=utf-8hibernate.dialect=org.hibernate.dialect.MySQLDialectjdbc.username=rootjdbc.password=adminpool.initialSize=20pool.maxActive=40pool.maxIdle=5pool.maxWait=600pool.poolPreparedStatements=falsepool.defaultAutoCommit=falsepool.timeBetweenEvictionRunsMillis=3600000pool.minEvictableIdleTimeMillis=3600000#hibernate c3p0 settingsc3p0.acquireIncrement=1 c3p0.maxIdleTime=60 c3p0.maxPoolSize=10 c3p0.minPoolSize=2 c3p0.initialPoolSize=5 #hibernate settingshibernate.show_sql=truehibernate.format_sql=falsehibernate.auto=updatehibernate.ehcache_config_file=ehcache.xmlhibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProviderhibernate.jdbc.batch_size=20
?

读书人网 >编程

热点推荐