spring boot @ConfigurationProperties @EnableConfigurationProperties 配置注解使用
来源:互联网 发布:手绘软件手机版 编辑:程序博客网 时间:2024/05/14 13:23
- @ConfigurationProperties使用
application-dev.yml
my: servers: port: 8080 threadPool: maxThreads: 100 minThreads: 8 idleTimeout: 6000
@ConfigurationProperties 使用
** * Created by jiyang on 16:10 2017/12/15 */@Controller@RequestMapping("/tester")@Api(value = "测试页面", description = "测试页面相关接口")@ConfigurationProperties(prefix = "my.servers")public class TestController { @Getter @Setter private int port; @Getter @Setter private Map<String,Object> threadPool;}
2.@EnableConfigurationProperties
//file MyWebServerConfigurationProperties.javaimport org.springframework.boot.context.properties.ConfigurationProperties;@ConfigurationProperties(prefix = "my.webserver")public class MyWebServerConfigurationProperties { private int port; private ThreadPool threadPool; public int getPort() { return port; } public void setPort(int port) { this.port = port; } public ThreadPool getThreadPool() { return threadPool; } public void setThreadPool(ThreadPool threadPool) { this.threadPool = threadPool; } public static class ThreadPool { private int maxThreads; private int minThreads; private int idleTimeout; public int getIdleTimeout() { return idleTimeout; } public void setIdleTimeout(int idleTimeout) { this.idleTimeout = idleTimeout; } public int getMaxThreads() { return maxThreads; } public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; } public int getMinThreads() { return minThreads; } public void setMinThreads(int minThreads) { this.minThreads = minThreads; } }}
// file: MyWebServerConfiguration.javaimport org.springframework.context.annotation.Configuration;import org.springframework.boot.context.properties.EnableConfigurationProperties;@Configuration@EnableConfigurationProperties(MyWebServerConfigurationProperties.class)public class MyWebServerConfiguration { @Autowired private MyWebServerConfigurationProperties properties; /** *下面就可以引用MyWebServerConfigurationProperties类 里的配置了 */ public void setMyconfig() { String port = properties.getPort(); // ........... }
阅读全文
0 0
- spring boot @ConfigurationProperties @EnableConfigurationProperties 配置注解使用
- 在Spring Boot中使用 @ConfigurationProperties 注解
- spring boot:使用@ConfigurationProperties注解加载配置文件
- spring boot 使用@ConfigurationProperties
- spring boot 使用@ConfigurationProperties
- spring boot 使用@ConfigurationProperties
- Spring Boot 使用@ConfigurationProperties注解获取配置文件中的值
- 4、@ConfigurationProperties和@EnableConfigurationProperties配合使用
- 学习Spring boot 注解 @Value @Component @ConfigurationProperties
- spring boot 通过@Value,@ConfigurationProperties获取配置
- 在spring-boot中使用@ConfigurationProperties
- Spring boot @ConfigurationProperties
- spring-boot @ConfigurationProperties脑洞真大
- spring-boot配置(一):@Configuration,@ConfigurationProperties和application.yml
- Using @ConfigurationProperties in Spring Boot
- Spring boot源码分析-ConfigurationProperties
- Spring Boot第四弹:Spring Boot之@Value和@ConfigurationProperties
- spring boot 注解配置redis
- Linux定时任务Crontab命令详解
- Spring Boot
- 【阿里云MVP月度分享】如何基于MYSQL做实时计算?
- Maven根据Profile读取不同配置环境配置文件
- hibernate入门-------eclipse环境搭建
- spring boot @ConfigurationProperties @EnableConfigurationProperties 配置注解使用
- 关于https路径下应用http资源问题
- Elasticsearch大文件检索性能提升20倍实践(干货)
- Rhyme/Spring 完整学习笔记
- Maven根据不同环境打包不同配置文件
- 二维数组—S型排座问题
- 前端优化系列
- javascript事件篇
- C语言面试题---指针篇(五)