spring.xml文件: <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> <property name="url" value="jdbc:sqlserver://192.168.1.69;dataBaseName=TMS" /> <property name="username" value="sa" /> <property name="password" value="sql" /> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="classpath:sqlmap.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="DataBaseImpl" class="com.publicsoft.database.DataBaseImpl"> <property name="sqlMapClient" ref="sqlMapClient" /> </bean> <import resource="classpath:spring-xt.xml"/> spring-xt.xml文件: <beans> <bean id="loginActionSpring" class="com.publicsoft.xt.LoginAction" scope="prototype"> <property name="database" ref="DataBaseImpl" /> </bean> </beans> struts.xml文件: <struts> <include file="/struts-xt.xml"></include> </struts> struts-xt.xml文件: <struts> <constant name="struts.i18n.encoding" value="GB2312" /> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="default" extends="struts-default"> <global-results> <result name="xtException">/xt/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="xtException" /> </global-exception-mappings> </package> <package name="xt" namespace="/xt" extends="default"> <!-- 登录信息 --> <action name="login" class="loginActionSpring" > <result name="success">/xt/mainframe.jsp</result> </action> </package> </struts> sqlmap.xml文件: <sqlMapConfig> <!-- 该文件是sql-map-config.xml文件改名而来,是iBatis专用文件 --> <sqlMap resource="sqlmap-xt.xml"/> </sqlMapConfig> sqlmap-xt.xml文件: <sqlMap namespace="xt"> <select id="qryD_XT_KEYS" resultClass="java.lang.Integer" parameterClass="java.util.Map"> exec tools_xt_keybuilder #table_name#,#field_name# </select> <select id="qryD_XT_BASECODE" resultClass="java.util.HashMap" parameterClass="java.lang.String"> select SCOPE_ID,SCOPE_DES,BASECODE_NO,BASECODE_VALUE,BASECODE_NAME,BASECODE_DES from d_xt_basecode where $filter$ order by order_id </select> </sqlMap> web.xml文件: <web-app id="WebApp_9" version="2.4"> <!--配置SPRING的BEAN管理文件,默认情况下会到WEB-INF/下去找applicationContext.xml --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring.xml, classpath:service.xml </param-value> </context-param> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>struts-cleanup</filter-name> <filter-class> org.apache.struts2.dispatcher.ActionContextCleanUp </filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- begin XFire 配置 --> <servlet> <servlet-name>xfire</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>xfire</servlet-name> <url-pattern>*.ws</url-pattern> </servlet-mapping> <servlet> <!-- 配合Spring容器中XFire一起工作的Servlet--> <servlet-name>xfireServlet</servlet-name> <servlet-class> org.codehaus.xfire.spring.XFireSpringServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>xfireServlet</servlet-name> <!-- 在这个URI下开放Web Service服务 --> <url-pattern>/service/*</url-pattern> </servlet-mapping> <!-- end XFire 配置 --> 相关代码如上,多个数据源的数据库名称相同(TMS),表结构相同,只是数据内容不同而已,现在需要配置多个数据源,如何配置,望高人指点! |
|
50分 |
<bean id=”dataSource”
class=”org.springframework.jdbc.datasource.DriverManagerDataSource”> <property name=”driverClassName” value=”com.microsoft.sqlserver.jdbc.SQLServerDriver” /> <property name=”url” value=”jdbc:sqlserver://192.168.1.69;dataBaseName=TMS” /> <property name=”username” value=”sa” /> <property name=”password” value=”sql” /> </bean> 多配置几个就行了,在代码用切换 |
数据源比较多,大概有20多个,如果用代码切换肯定会影响效率的,所以想用配置文件来替换,不知道怎么入手! |
|
50分 |
<bean id=”dataSource”
class=”org.springframework.jdbc.datasource.DriverManagerDataSource”> <property name=”driverClassName” value=”${}” /> <property name=”url” value=”${}” /> <property name=”username” value=”${}” /> <property name=”password” value=”${}” /> </bean> 那你就采用这用方式,写一个properties文件,修改properties文件吧 |
用代码怎么切换啊,也遇到了这样的问题,配置了两个数据源,分别注入到sqlMapClient,但是到dao层怎样切换不同的数据源啊?
|