[英]How to add multiple google cloud datasources using spring
I have two sql datasources already working locally, but I want to deploy it to two google cloud app-engines (I have it working with one right now). 我有两个已经在本地工作的sql数据源,但是我想将其部署到两个google cloud应用程序引擎(我现在正在使用一个)。 What do I need to change in my application-properties to define a second google instance/database?
我需要在我的应用程序属性中进行更改以定义第二个Google实例/数据库吗?
I already have links set up in my pom for connections called sql.instance.second
and sql.database.second
. 我已经在pom中设置了名为
sql.instance.second
和sql.database.second
连接sql.database.second
。 I don't know how to define spring.cloud.gcp.sql...
for a second app-engine. 我不知道如何为第二个应用程序引擎定义
spring.cloud.gcp.sql...
Another option I have is to not run it locally at all but just define a cloud instance when I'm defining the datasources and then define a driver for each, but I'm not too sure how to do that either. 我还有另一个选择是根本不本地运行它,而只是在定义数据源时定义一个云实例,然后为每个定义一个驱动程序,但是我也不知道该怎么做。
spring.cloud.gcp.sql.instance-connection-name=@sql.instance.first@
spring.cloud.gcp.sql.database-name=@sql.database.first@
primary.datasource.jdbc-url = @mysql.host.first@
primary.datasource.username = @mysql.user.first@
primary.datasource.password = @mysql.pass.first@
secondary.datasource.jdbc-url = @mysql.host.second@
secondary.datasource.username = @mysql.user.second@
secondary.datasource.password = @mysql.pass.second@
I was able to get it working by getting rid of this dependency first 我可以通过首先摆脱这种依赖来使其工作
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
</dependency>
Then changing my application.properties
to this 然后将我的
application.properties
更改为此
primary.datasource.driverClassName=com.mysql.jdbc.GoogleDriver
primary.datasource.jdbc-url = @mysql.host.first@
primary.datasource.username = @mysql.user.first@
primary.datasource.password = @mysql.pass.first@
secondary.datasource.driverClassName=com.mysql.jdbc.GoogleDriver
secondary.datasource.jdbc-url = @mysql.host.second@
secondary.datasource.username = @mysql.user.second@
secondary.datasource.password = @mysql.pass.second@
And deleting 并删除
spring.cloud.gcp.sql.instance-connection-name=@sql.instance.first@
spring.cloud.gcp.sql.database-name=@sql.database.first@
Change the url of @mysql.host.first@
in my pom.xml to 将我的pom.xml中的
@mysql.host.first@
的URL更改为
<mysql.host.first>jdbc:google:mysql:...</mysql.host.first>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.