applicationContext.xml整合hibernate mybatis

前端之家收集整理的这篇文章主要介绍了applicationContext.xml整合hibernate mybatis前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd" default-lazy-init="true"> <description>Spring公共配置</description> <!-- 使用annotation 自动注册bean,并检查@required,@Autowired的属性已被注入 --> <context:component-scan base-package="com.creditcities.crm"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <context:component-scan base-package="com.creditcities.framework"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <context:component-scan base-package="com.creditcities.security"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <context:component-scan base-package="com.creditcities.sysaudit"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- 定义受环境影响易变的变量 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <!-- 标准配置 --> <value>classpath*:/application.properties</value> <!-- 本地开发环境配置 --> <value>classpath*:/application.local.properties</value> <!-- 服务器生产环境配置 --> <value>file:/opt/application.server.properties</value> </list> </property> </bean> <cache:annotation-driven cache-manager="cacheManager"/> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" /> <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerfactorybean" p:shared="true" p:config-location="classpath:/ehcache.xml" /> <!-- <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> <property name="caches"> <set> <bean class="org.springframework.cache.concurrent.ConcurrentMapCachefactorybean" p:name="default" /> <bean class="org.springframework.cache.concurrent.ConcurrentMapCachefactorybean" p:name="andCache" /> </set> </property> </bean> --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/crm"/> --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionfactorybean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.creditcities.crm.repository.*.model</value> <value>com.creditcities.sysaudit.model</value> <value>com.creditcities.framework.model</value> <value>com.creditcities.security.repository.model</value> <value>com.creditcities.framework.security.model</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop> </props> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- MyBatis配置 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.sqlSessionfactorybean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:/mapper/Configuration.xml" /> <property name="mapperLocations" value="classpath:/mapper/*Mapper.xml" /> </bean> <bean id="sqlSessionTemplate" class="org.mybatis.spring.sqlSessionTemplate"> <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> <bean id="hibernateDao" class="com.creditcities.framework.orm.hibernate.HibernateDao"> <property name="hibernateTemplate" ref="hibernateTemplate" /> </bean> <bean id="mybatisDao" class="com.creditcities.framework.orm.mybatis.MybatisDao"> <property name="sqlSessionTemplate" ref="sqlSessionTemplate" /> </bean> <bean id="dao" class="com.creditcities.framework.orm.Dao"> <property name="hibernateTemplate" ref="hibernateTemplate" /> <property name="sqlSessionTemplate" ref="sqlSessionTemplate" /> </bean> <!-- 事务管理器配置 --> <bean id="defaultTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="defaultTransactionManager" /> <property name="transactionAttributeSource"> <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" /> </property> </bean> <bean id="txAttributeSourceAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="txInterceptor" /> </bean> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" /> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- one of the properties available; the maximum file size in bytes --> <property name="maxUploadSize" value="100000" /> </bean> <!-- mongodb setings --> <mongo:mongo id="mongo" host="${mongodb.host}" port="${mongodb.post}"> <mongo:options connections-per-host="8" threads-allowed-to-block-for-connection-multiplier="4" connect-timeout="1000" max-wait-time="1500" auto-connect-retry="true" socket-keep-alive="true" socket-timeout="1500" slave-ok="true" write-number="1" write-timeout="0" write-fsync="true" /> </mongo:mongo> <mongo:db-factory id="mongoFactory" dbname="${mongodb.dbname}" mongo-ref="mongo" username="${mongodb.username}" password="${mongodb.password}" /> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoFactory" /> </bean> <!-- SpringContextHolder定义 --> <bean class="com.creditcities.framework.utils.SpringContextHolder" lazy-init="false" /> <bean id="restClient" class="com.creditcities.framework.service.RestClient"> <constructor-arg value="${service.client.url}"></constructor-arg> </bean> <bean id="remoteClient" class="com.creditcities.framework.service.RemoteClient"> <constructor-arg value="${remote.content.call.url}"></constructor-arg> </bean> <bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="${mail.server.host}"></property> <property name="port" value="${mail.server.port}"></property> <property name="username" value="${mail.server.username}"></property> <property name="password" value="${mail.server.password}"></property> <property name="defaultEncoding" value="${mail.server.defaultEncoding}"></property> <property name="javaMailProperties"> <props> <prop key="mail.debug">true</prop> <!-- <prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> --> <prop key="mail.smtp.auth">true</prop> </props> </property> </bean> <!-- 国际化的消息资源文件 --> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找 --> <value>classpath:ValidationMessages</value> </list> </property> <property name="defaultEncoding" value="UTF-8" /> <property name="cacheSeconds" value="60" /> </bean> </beans>

猜你在找的XML相关文章