SpringBoot配置Apollo代码实例
更新时间:2019年10月18日 11:20:33 作者:notMore
这篇文章主要介绍了SpringBoot配置Apollo代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
这篇文章主要介绍了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包后,项目配置
入口方法加入注解配置
@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;
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
SpringBoot+ShardingSphereJDBC实现读写分离详情
这篇文章主要介绍了SpringBoot+ShardingSphereJDBC实现读写分离详情,通过用MySQL进行一主一从的主从复制展开全文内容,需要的朋友可以参考一下2022-08-08
Spring应用抛出NoUniqueBeanDefinitionException异常的解决方案
这篇文章介绍了解决org.springframework.beans.factory.NoUniqueBeanDefinitionException异常的一些解决方案,从这些解决方案可以看出Spring框架的设计精妙,遇见此问题的朋友可以参考下该解决方案2021-06-06
springboot整合mybatis plus与druid详情
这篇文章主要介绍了springboot整合mybatis plus与druid详情,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的下伙伴可以参考一下2022-09-09


最新评论