使用 Spring Cloud 设置数据源 [英] Setting datasources with Spring Cloud
问题描述
我正在寻找一个简单的示例,用于从运行 Spring Cloud 的配置服务器设置数据源 (jdbc).我已经阅读了 Spring Cloud 的 Spring.io 文档,发现它们非常令人困惑.
I am looking for a SIMPLE example for setting a datasource (jdbc) from a configuration server running Spring Cloud. I've read through the Spring.io docs for Spring Cloud and find them VERY confusing.
有谁知道可以找到一个简单示例的地方?我试图运行他们在 Github 上的东西,但他们没有构建.
Does anyone know of a place to find a simple example? I've tried to run the stuff they have on Github, but they don't build.
推荐答案
配置数据源与 vanilla spring boot除了配置将从 spring-cloud 配置服务器加载.因此,不是将属性放在 application.properties
中,而是将它放在
中,其中
是spring.application.name
中定义的应用程序名称.
Configuring a datasource is the same as in vanilla spring boot
with the exception that the configuration will be loaded from a spring-cloud config server. So instead of putting the properties in application.properties
, you put it in <myapplication>.properties
, where <myapplication>
is the name of your app defined in spring.application.name
.
因此,如果您的应用名为 myapplication
,那么您将以下内容放入 myappliction.properties
(由配置服务器托管):
So if your app is named myapplication
, then you put the following in myappliction.properties
(which is hosted by the config server):
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
这篇关于使用 Spring Cloud 设置数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!