SpringBoot之配置文件及自定义参数
2016-12-01 22:42
721 查看
今天对SpringBoot配置文件application.properties中部分配置以及profile多环境简单说明。
SpringBoot 默认加载配置文件application.properties,通过配置profiles属性实现多环境部署。
将配置文件通过@Value注解形式注入进来
你看。。。
哇哦,竟然给注入进来了。。。
SpringBoot 默认加载配置文件application.properties,通过配置profiles属性实现多环境部署。
1.配置文件application.properties部分说明
#自定义服务器端口 server.port=8990 # 多环境配置文件激活属性(dev/prod/test) spring.profiles.active=dev
2.自定义参数注入
在application.properties文件中定义参数如下:#项目基本属性 com.venus.config.project.name=Learn com.venus.config.project.version=v1
将配置文件通过@Value注解形式注入进来
/** * 自定义参数注入 * @author Alan Liu * Created by on 2016/11/26 0026. */ @Component public class BaseConfig { //获取不到配置的值,默认赋值Test @Value("${com.venus.config.project.name}") private String name; @Value("${com.venus.config.project.version}") private String version; .... 此处省略setter和getter }
3. @Autowired注入实例
接下来看看参数有没有被注入进来呢。。。/** * Spring Boot 配置文件 以及多环境profile配置 * @author Alan Liu * Created on 2016/11/26 0026. */ @Controller public class PropertiesCtr { @Autowired BaseConfig baseConfig; @RequestMapping("/base-config") @ResponseBody public String test01(){ String returnMsg = baseConfig.getName() + ":"+ baseConfig.getVersion(); return returnMsg; } }
你看。。。
哇哦,竟然给注入进来了。。。
相关文章推荐
- SpringBoot中自定义properties文件配置参数并带有输入提示
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- springboot自定义配置文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- spring 获取自定义配置文件properties中参数
- SpringBoot自定义配置文件路径
- 五、Springboot 之 自定义配置文件及读取配置文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- Springboot 之 自定义配置文件及读取配置文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- 2、spring-boot 工程配置——配置文件详解:自定义属性、随机数、多环境配置等
- SpringBoot如何导入自定义配置的yml文件