首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

springmvc3诠注+mybatis+JTA+jboss7.1下多个数据源配置(二)

2013-11-18 
springmvc3注解+mybatis+JTA+jboss7.1下多个数据源配置(二)?xml version1.0 encodingUTF-8?beans

springmvc3注解+mybatis+JTA+jboss7.1下多个数据源配置(二)
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd "><!-- ***************资源文件 ************** --><!--<context:property-placeholder location="classpath*:dataSourceConfig.properties"/> --><!-- ************** DataSource: 连接池 ****************--><jee:jndi-lookup jndi-name="java:/oracle119" id="oracledataSource"lookup-on-startup="true"></jee:jndi-lookup><jee:jndi-lookup jndi-name="java:jboss/mysql127" id="mssqldataSource"lookup-on-startup="true"></jee:jndi-lookup><!-- ***************事务配置************** --><bean id="transactionManager" /><aop:config> <aop:advisor pointcut="execution(* service..*.*(..))" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="query*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="load*" read-only="true" /> <tx:method name="select*" read-only="true" /> <tx:method name="*" propagation="REQUIRED" rollback-for="Exception" /> </tx:attributes> </tx:advice> <tx:annotation-driven transaction-manager="transactionManager" /><!-- MyBatis 把mysql和oracle的mybatis映射xml 分开来放 --><bean id="oraclesqlSessionFactory" ref="oracledataSource" /> <property name="mapperLocations" value="classpath*:dao/oracleDb/**/*.xml"/> </bean><bean value="dao.oracleDb" /> <property name="sqlSessionFactoryBeanName" value="oraclesqlSessionFactory" /></bean> <bean id="mssqlSessionFactory" ref="mssqldataSource" /> <property name="mapperLocations" value="classpath*:dao/mssqlDb/**/*.xml"/> </bean><bean value="dao.mssqlDb" /> <property name="sqlSessionFactoryBeanName" value="mssqlSessionFactory" /></bean> </beans>

?

?

?这个配置文件 是springmvc3里面只是核心的配置供大家参考。 其余还有jsp路径,还有controller ?service层的注解,还有拦截器 在另外一个配置里面 ,分开写好调试

?

首先 前面使用了jee:jndi-lookup 这种方式获取了数据源, 要在xml最上面的声明那里 加入xmlns:jee="http://www.springframework.org/schema/jee 和下面xsi:schemaLocation里的 jee

才能正常使用

?

其次 bean ?id="transactionManager?" ?这个需要使用?

org.springframework.transaction.jta.JtaTransactionManager

这里并不需要指定数据源datasource属性?

详细请见:http://docs.spring.io/spring/docs/3.0.x/reference/transaction.html

?

springmvc3诠注+mybatis+JTA+jboss7.1下多个数据源配置(二)Note

If you use JTA , then your transaction manager definition will look the same regardless of what data access technology you use, be it JDBC, Hibernate JPA or any other supported technology. This is due to the fact that JTA transactions are global transactions, which can enlist any transactional resource.

?

?最后 核心的mybatis和springmvc结合的地方,<bean id="oraclesqlSessionFactory"到最后

是我以前采用咿呀网 狼哥提供的单数据源配置修改而来,这种方式 好处就是 把不同的数据库里需要映射的mybatis配置,分开放,启动应用的时候 可以直接扫描,实现自动加载,(看过几片文章,发现这种方式不是最好的,但是 英文才 也只能勉强到这里了。)

热点排行