oracle的另外一种分布式调用

xiaoxiao2024-12-20  23

在spring的配置文件中 配置sessionFactory 指定数据源名称 <bean id="[color=red]sessionFactoryByTpiAttemper[/color]" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="[color=red]dataSourceByTPI[/color]" /> </property> <property name="lobHandler" ref="oracleLobHandler"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${db.dialect}</prop> <!--prop key="hibernate.hbm2ddl.auto">validate</prop--> <prop key="hibernate.show_sql">${db.show_sql}</prop> <prop key="hibernate.format_sql">${db.format_sql}</prop> <prop key="hibernate.use_sql_comments"> ${db.use_sql_comments} </prop> <prop key="hibernate.default_batch_fetch_size">16</prop> <prop key="hibernate.jdbc.fetch_size">30</prop> <prop key="hibernate.jdbc.batch_size">25</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.OSCacheProvider </prop> <prop key="hibernate.query.factory_class"> org.hibernate.hql.classic.ClassicQueryTranslatorFactory </prop> <prop key="hibernate.transaction.manager_lookup_class"> org.hibernate.transaction.JOTMTransactionManagerLookup </prop> <prop key="jta.UserTransaction"> java:comp/env/UserTransaction </prop> </props> </property> <property name="mappingLocations"> <list> <value>classpath*:com/mip/biz/attopbill/tpiattemperdomain/hbm/*.hbm.xml</value> </list> </property> </bean> 给指定的类 指定 连接的sessionFatory <bean id="com.yourcompany.biz. pbill.services.TaboperateticketService" class="com. yourcompany.biz. pbill.services.imp.TaboperateticketServiceImp" > <property name="sessionFactory"> <ref bean="[color=red]sessionFactoryByTpiAttemper[/color]"/> </property> </bean> 然后在数据源的配置文件中 配置 数据源 <bean id="[color=red]dataSourceByTPI[/color]" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="close"> <property name="driver" value="${tpi_db.driver}"/> <property name="driverUrl" value="${tpi_db.url}"/> <property name="user" value="${tpi_db.username}"/> <property name="password" value="${tpi_db.password}"/> <property name="alias" value="${tpi_db.username}"/> <property name="houseKeepingSleepTime" value="9000"/> <property name="prototypeCount" value="5"/> <property name="maximumConnectionCount" value="5"/> <property name="minimumConnectionCount" value="2"/> <property name="trace" value="true"/> <property name="verbose" value="true"/> </bean> 最后在连接数据库的配置文件中 指定URL username password 等等 tpi_db.url=jdbc\:oracle\:thin\:workplan/password@192.168.12.11\:1521\:test tpi_db.username=workplan tpi_db.password= password 这里有个问题 username 的值可以和url中指定的登陆用户名及密码不一致 也是可以运行成功的 貌似是备用的 URL中找不到,才去匹配username和password连接数据库 [color=red]这样可以在同一个services类中,注入连接了不同数据库的dao实现类,貌似也可以这样在一个系统中,实现oracle数据库的分布式调用,就是不知道跟 oracle的 DB_LINK各有什么优势和缺点[/color]
转载请注明原文地址: https://www.6miu.com/read-5021560.html

最新回复(0)