Coder Social home page Coder Social logo

tomato1024 / springboot-disconf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from l316476844/springboot-disconf

0.0 1.0 0.0 30 KB

springboot结合百度开源disconf做配置中心使用,使用xml方式配置数据源及事务,xml方式使用mybatis mapper和plugin。使用druid数据源监控过滤sql。添加api拦截器功能。

Java 100.00%

springboot-disconf's Introduction

springboot-disconf

springboot结合百度开源disconf做配置中心使用,使用xml方式配置数据源及事务,xml方式使用mybatis mapper和plugin。使用druid数据源监控过滤sql。添加api拦截器功能。

  1. 在pom中添加disconf和zk的配置如下:
   <dependency>
      <groupId>org.apache.zookeeper</groupId>
      <artifactId>zookeeper</artifactId>
      <version>3.4.6</version>
    </dependency>
    
    <dependency>
      <groupId>com.baidu.disconf</groupId>
      <artifactId>disconf-client</artifactId>
      <version>2.6.36</version>
    </dependency> 
  1. 添加xml配置可参考示例中config/application-disconf.xml:

  2. 在classpath下添加Disconf Client的用户配置文件 disconf.properties 和 Disconf 系统自带的配置 disconf_sys.properties。

  3. SpringBootApplication 启动类添加注解@ImportResource({"classpath:config/application-disconf.xml"})//引入disconf

  4. 获取分布式的配置文件中的ITEM。可通过两种方式

  • 百度开源作者提供的在get方法上使用disconf注解获取的方式如下:
    @DisconfFileItem(name = "app.host")
    public String getHost() {
        return host;
    }
    此种方式的前提条件是必须在定义的组件上使用 @DisconfFile(filename = "app_env.properties")获取配置文件如下:
    @Component
    @Scope("singleton")
    @DisconfFile(filename = "app_env.properties")
    public class AppConfig {}
  • 另外一种方式是使用spring注解的方式加载如下:
    /**
     * spring 获取配置的方式
     */
    @Value("${app.host}")
    private String host;

  • 以上两种方式都可动态获取diconf配置中心改变的ITEM配置(亲测通过)。

springboot-disconf's People

Contributors

l316476844 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.