Spring Boot 之注解@Component @ConfigurationProperties(prefix = "sms")
从spring-boot开始,已经支持yml文件形式的配置,@ConfigurationProperties的大致作用就是通过它可以把properties或者yml配置直接转成对象
例如:
配置文件:
sms.url=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sms.appkey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sms.secret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sms.signName=XXXXXXXXXXXXXXXXXXXXXXXXXXX
sms.tplCode=XXXXXXXXXXXXXXXXXXXXXXXXXXXX
sms.type=normal
JAVA代码:
@Component
@ConfigurationProperties(prefix = "sms")
public class SmsSettings { private String url ="";
private String appkey ="";
private String secret ="";
private String signName ="";
private String tplCode ="";
private String type ="";
private String open ="";
private String tplCode2 =""; public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAppkey() {
return appkey;
}
public void setAppkey(String appkey) {
this.appkey = appkey;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getSignName() {
return signName;
}
public void setSignName(String signName) {
this.signName = signName;
}
public String getTplCode() {
return tplCode;
}
public void setTplCode(String tplCode) {
this.tplCode = tplCode;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getOpen() {
return open;
}
public void setOpen(String open) {
this.open = open;
}
public String getTplCode2() {
return tplCode2;
}
public void setTplCode2(String tplCode2) {
this.tplCode2 = tplCode2;
} }
通过注解@ConfigurationProperties来配置redis @Configuration
@EnableAutoConfiguration
public class RedisConfig { @Bean
@ConfigurationProperties(prefix="spring.redis.poolConfig")
public JedisPoolConfig getRedisConfig(){
JedisPoolConfig config = new JedisPoolConfig();
return config;
} @Bean
@ConfigurationProperties(prefix="spring.redis")
public JedisConnectionFactory getConnectionFactory(){
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setUsePool(true);
JedisPoolConfig config = getRedisConfig();
factory.setPoolConfig(config);
return factory;
} @Bean
public RedisTemplate<?, ?> getRedisTemplate(){
RedisTemplate<?,?> template = new StringRedisTemplate(getConnectionFactory());
return template;
} }
Spring Boot 之注解@Component @ConfigurationProperties(prefix = "sms")的更多相关文章
- Spring Boot 之注解@Component @ConfigurationProperties(prefix = "sms") 使用@ConfigurationProperties读取yml配置
从spring-boot开始,已经支持yml文件形式的配置,@ConfigurationProperties的大致作用就是通过它可以把properties或者yml配置直接转成对象 @Componen ...
- spring boot常用注解使用小结
1.@RestController和@RequestMapping注解 4.0重要的一个新的改进是@RestController注解,它继承自@Controller注解. 4.0之前的版本,Sprin ...
- Spring Boot中注解@ConfigurationProperties
在Spring Boot中注解@ConfigurationProperties有三种使用场景,而通常情况下我们使用的最多的只是其中的一种场景.本篇文章带大家了解一下三种场景的使用情况. 场景一 使用@ ...
- Spring Boot常用注解总结
Spring Boot常用注解总结 @RestController和@RequestMapping注解 @RestController注解,它继承自@Controller注解.4.0之前的版本,Spr ...
- Spring Boot配置文件详解-ConfigurationProperties和Value优缺点-(转)好文
文章转自 http://www.cnblogs.com/itdragon/p/8686554.html Spring Boot提供了两种常用的配置文件,分别是properties文件和yml文件.他们 ...
- Spring boot 基于注解方式配置datasource
Spring boot 基于注解方式配置datasource 编辑 Xml配置 我们先来回顾下,使用xml配置数据源. 步骤: 先加载数据库相关配置文件; 配置数据源; 配置sqlSessionF ...
- Spring Boot 常用注解汇总
一.启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documen ...
- 3个Spring Boot核心注解,你知道几个?
Spring Boot 核心注解讲解 Spring Boot 最大的特点是无需 XML 配置文件,能自动扫描包路径装载并注入对象,并能做到根据 classpath 下的 jar 包自动配置. 所以 S ...
- 【SpringBoot】15. Spring Boot核心注解
Spring Boot核心注解 1 @SpringBootApplication 代表是Spring Boot启动的类 2 @SpringBootConfiguration 通过bean对象来获取配置 ...
随机推荐
- 【BZOJ1717】[Usaco2006 Dec]Milk Patterns 产奶的模式 后缀数组
[BZOJ1717][Usaco2006 Dec]Milk Patterns Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量 ...
- Swift - 触摸事件响应机制(UiView事件传递)
import UIKit class FatherView: UIView { override func hitTest(point: CGPoint, withEvent event: UIEve ...
- ionic+cordova开发!
这里是一些学习的过程中纪录的: 官方网站: http://www.ionic-china.com/ 参考文章: https://blog.csdn.net/xyzz609/article/detail ...
- MariaDB登陆
设置root密码 “mariabd”是新密码 [root@master /]# mysqladmin -u root password mariadb [root@master /]# mysql - ...
- [EF]vs15+ef6+mysql这个问题,你遇到过么?
写在前面 因为最近用mysql比较多,所以想了解下ef+mysql的内容,发现ef连接mysql数据库,还有那么一段路折腾.折腾到最后,发疯了. 步骤 这里采用db first的方式来使用ef. 通过 ...
- Spring-Boot整合freemarker引入静态资源css、js等
一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...
- 终于修好了MacBook
之前由于Trackpad故障,陆家嘴苹果店开了维修单,让我在2周内去更换,详见第二次去苹果店维修MacBook. 后来由于购买了AppleCare进行延保,又担心放在那维修时间长,就懒得去更换了. 昨 ...
- Drools规则引擎
一.简介 Drools is a Business Rules Management System (BRMS) solution. It provides a core Business Rules ...
- Educational Codeforces Round 29
A. Quasi-palindrome 题目链接:http://codeforces.com/contest/863/problem/A 题目意思:问一个数可不可以在不上一些前缀0以后变成一个回文数. ...
- 把大象装进冰箱的N种方法
作者:折剑头链接:https://www.zhihu.com/question/49214119/answer/115728034来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...