xuxueli / xxl-conf

A lightweight distributed configuration management platform. (分布式配置管理平台XXL-CONF)
http://www.xuxueli.com/xxl-conf/
GNU General Public License v3.0
666 stars 371 forks source link

在SpringCloud项目中,怎么配置数据库和其他配置属性? #49

Closed huaijinwoyu closed 5 years ago

huaijinwoyu commented 6 years ago

RT,现在微服务中,需要对不同的环境进行测试和打包. 我是用application.properties 配合maven+spring.profiles.active来实现生产和测试的打包. 现在想引入线上配置文件,spring cloud config 不太灵活,我在研究你的xxl-conf-sample-springboot中,有一点困惑, 像数据库的配置文件 spring.datasource.url=XXX 都是写在配置文件中.,不太了解怎么用xxl-xonf来替换现有的配置文件.

wanwujiedao commented 5 years ago

感觉没有 xdiamond 好用啊

xuxueli commented 5 years ago

你好,文档提供了多种配置加载方式:Api、注解、Xml占位符、Listener……等等,可以任意选择一种使用。

比如注解方式:

@XxlConf("default.key02")
public String paramByAnno;

更多可参考文档:http://www.xuxueli.com/xxl-conf/

ColorfulGhost commented 5 years ago

同问,spring.datasource.url=XXX 像这种配置方式我看demo注解里使用

{T(com.xxl.conf.core.XxlConfClient).get('xxxxl')}

这种方法来配置 但是在Spring Boot sample 我没有看到如下XML配置

<bean id="demoConf" class="com.xxl.conf.sample.demo.DemoConf2">
    <constructor-arg index="0" value="#{T(com.xxl.conf.core.XxlConfClient).get('key')}" />
    <property name="paramByXml" value="#{T(com.xxl.conf.core.XxlConfClient).get('default.key03')}" />
</bean>