Setting datasources with Spring Cloud

半腔热情 提交于 2019-12-11 05:36:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!