First, customize a configuration file in the resources directory
As sms.properties
# SMS platform related mall.sms.regionId = CH- o hangzhou mall.sms.accessKeyId = ********* mall.sms.accessKeySecret = ********** mall.sms.product = Dysmsapi mall.sms.domain = dysmsapi.aliyuncs.com mall.sms.timeout = 1000 mall.sms.signName = Jingan international nations Hui Park mall.sms.templateCode = SMS_150172034 mall.sms.templateParam = {\ "code \": \ "@ code @ \"} mall.sms.verify.timeout = 600
Annotate @PropertySource need in this class configured
@Service @Slf4j @PropertySource(value="classpath:sms.properties",encoding = "utf-8") public class SmsService { @Autowired private RedisManager redisManager; @Value("${mall.sms.signName}") private String signName; @Value("${mall.sms.templateCode}") private String templateCode; @Value("${mall.sms.templateParam}") private String templateParam; @Value("${mall.sms.verify.timeout}") private long timeout; }
@PropertySource annotation value of the value of classpath: profile name
Finally, there are two points to note:
First: the need to pay attention to the file format properties should be set to utf-8
@PropertySource not only need to add value attributes and then reads the configuration file, you need to set encoding to utf-8