【发布时间】:2016-03-27 15:26:22
【问题描述】:
我有一个使用 MySQL、Spring 和 tomcat 服务器的工作程序,但数据库连接在 spring-database.xml 中:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="baseController" class="com.afterguard.sailplanner.controller.BaseController">
<property name="dao" ref="daoImpl" />
</bean>
<bean id="daoImpl" class="com.afterguard.sailplanner.dao.DaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/sailplanner" />
<property name="username" value="sailplanner" />
<property name="password" value="sailplanner2" />
</bean>
</beans>
现在为了在服务器上部署这个程序,我需要把这个数据库连接带到服务器上,例如context.xml 和 server.xml。
如何设置我的 tomcat 7 服务器以连接到数据库并告诉我的应用程序,数据库连接已在 tomcat 中设置?
【问题讨论】:
-
你想要什么不清楚,请说明你的要求。
-
好的,我试图澄清这个问题。
-
将数据库连接带到服务器是什么意思?在其上创建一个数据库连接,或者只是将 XML 文件部署到您的应用程序中?
-
我从你的问题中了解到的你想在你的 applicationContext.xml 文件中使用 spring-database.xml 如果是,那么你应该在 applicationContext.xml 文件中编写这段代码