解决spring-boot项目中无法读取yml配置文件属性问题
2017-12-22 14:12
1586 查看
1.创建Config:
2.增加gradle依赖:
3.在项目中使用:
package com.ftvalue.customer.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; /** * Created by 郝丹辉 on 2017/9/20. */ @Configuration public class YmlConfig { @Value("${ismpProps.ismpEimsSms}") private String ismpEimsSms; @Value("${ismpProps.ismpEimsEmail}") private String ismpEimsEmail; @Value("${ismpProps.userId}") private String userId; @Value("${ismpProps.userPwd}") private String userPwd; 4000 @Value("${ismpProps.account}") private String account; @Value("${templateNo}") private String templateNo; @Value("${role_Num}") private int role_Num; @Value("${ismpProps.ismpUrl}") private String ismpUrl; @Value("${ismpProps.ftsercurity}") private String ftsercurity; public String getIsmpEimsSms() { return ismpEimsSms; } public void setIsmpEimsSms(String ismpEimsSms) { this.ismpEimsSms = ismpEimsSms; } public String getIsmpEimsEmail() { return ismpEimsEmail; } public void setIsmpEimsEmail(String ismpEimsEmail) { this.ismpEimsEmail = ismpEimsEmail; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getUserPwd() { return userPwd; } public void setUserPwd(String userPwd) { this.userPwd = userPwd; } public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getTemplateNo() { return templateNo; } public void setTemplateNo(String templateNo) { this.templateNo = templateNo; } public String getIsmpUrl() { return ismpUrl; } public void setIsmpUrl(String ismpUrl) { this.ismpUrl = ismpUrl; } public int getRole_Num() { return role_Num; } public void setRole_Num(int role_Num) { this.role_Num = role_Num; } public String getFtsercurity() { return ftsercurity; } public void setFtsercurity(String ftsercurity) { this.ftsercurity = ftsercurity; } }
2.增加gradle依赖:
compile 'org.springframework.boot:spring-boot-configuration-processor'
3.在项目中使用:
@Autowired private YmlConfig ymlConfig; //然后使用: ymlConfig.getAccount();
相关文章推荐
- 关于Spring boot中读取属性配置文件出现中文乱码的问题的解决
- 解决Spring配置文件无法读取properties属性问题
- 创建springboot项目时 yml或application.properties无效或无法读取的问题
- 解决eclipse创建spring boot项目加载不到application.properties配置文件的问题
- 基于maven管理的项目中spring+mybatis配置数据源读取不到properties属性文件的问题
- Eclipse安装了SpringSource Tool Suite插件后,编辑SpringBoot项目的yml配置文件仍然没有提示信息的解决办法
- Spring学习总结(20)——Spring加载多个项目properties配置文件问题解决
- spring-boot读取props和yml配置文件
- 解决maven同步的eclipse中的springboot项目无法启动问题
- 解决项目打jar包后无法获取配置文件的路径问题
- spring-boot读取props和yml配置文件
- 解决IIS7虚拟目录出现HTTP 错误 500.19(由于权限不足而无法读取配置文件)的问题
- springboot学习笔记2(拦截器,redis,授权登录,读取yml配置文件)
- spring boot 添加自定义配置文件并读取属性
- Spring boot 项目 maven的profile多环境配置 不自动替换变量的问题解决
- Spring Boot系列 - 4. 读取配置文件(application.yml)中的属性值
- SpringMVC + mybatis 无法读取JAR包中的XML配置文件问题
- spring-boot读取props和yml配置文件
- 关于Spring与mybatis整合无法读取配置文件的问题
- 解决IIS7虚拟目录出现HTTP 错误 500.19(由于权限不足而无法读取配置文件)的问题