SpringBoot 配置Apollo


Windows環境安裝下載,參考:https://github.com/ctripcorp/apollo

項目引用

 <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client</artifactId>
            <version>1.4.0</version>
        </dependency>

引入jar包后,項目配置

1.入口方法加入注解配置   

@EnableApolloConfig
package top.xzhand;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableApolloConfig
@MapperScan("top.xzhand.mapper")
public class JuneApplication {

    public static void main(String[] args){
        SpringApplication.run(JuneApplication.class,args);
    }
}

yml 文件配置項

# 阿波羅配置
app:
id: juneweb-apollo
apollo:
# 注冊路徑,阿波羅默認注冊配置 Eureka
meta: http://localhost:8080
bootstrap:
enabled: true
# 指定阿波羅中配置項名稱,多個用逗號隔開
namespaces: application

配置項獲取

package top.xzhand.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.xzhand.po.Profix;

@Configuration
@EnableAutoConfiguration
public class ApolloProperties {
    @Value("${juneweb-apollo}") //阿波羅配置中心中配置的key
    public String prefix;
    @Bean
    public Profix profix(){
        Profix p=new Profix();
        p.setP(prefix);
        System.out.println("prefix=========================**********"+prefix);
        return p;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM