问题
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.
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.
回答1:
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
.
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
回答2:
You Could also put It in application.yml if you have the yaml lib on your classpath
spring:
datasource:
url: jdbc:mysql
username: username
password: password
driver-class-name: com.mysql.jdbc.Driver
来源:https://stackoverflow.com/questions/28439839/setting-datasources-with-spring-cloud