Spring配置调用不同的数据库环境,如dev,int,uat,prod

时间:2011-12-28 02:59:42

标签: spring spring-jdbc

我有一个Java独立应用程序,它使用Spring核心容器和spring jdbc。我有不同的数据库环境,如dev,int,uat,prod。这些数据库配置详细信息和每个环境的数据源都在spring配置文件spring-beans.xml中与DAO bean一起配置。 现在我必须更新应用程序,就像我在运行应用程序时将特定的数据库环境(如dev,int,uat,prod)作为参数传递一样,应用程序将调用参数中提到的数据库。有什么出路吗?

1 个答案:

答案 0 :(得分:0)

我认为你应该使用spring和hibernate它更容易,或者你可以使用JDNI

db1Jndi=
jdbc.url=jdbc:mysql://localhost:3306/db1
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=root

db2Jndi=
jdbc.url=jdbc:mysql://localhost:3306/db2
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=root