第三节:SpringBoot使用properties配置文件实现多环境配置

来源:互联网 发布:网游数据提取 编辑:程序博客网 时间:2024/05/17 17:38

application.properties配置文件如下

 #配置属性占位符xiaowen.name="xiaowen"xiaowen.desc=${xiaowen.name} is successfully#配置tomcat端口server.port=8088#激活pplication-dev.properties配置文件spring.profiles.active=dev


application-dev.properties配置文件如下
xiaowen.age=18


WebController类

package com.xiaowen.controller;import java.util.HashMap;import java.util.Map;import org.springframework.beans.factory.annotation.Value;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class WebController {@Value("${xiaowen.name}")private String name;@Value("${xiaowen.desc}")private String desc;@Value("${xiaowen.age}")private int age;@RequestMapping("/index")public Map<String, Object> Index(){Map<String, Object> map=new HashMap<String, Object>();map.put("name", name);map.put("desc", desc);map.put("age", age);return map; }}
浏览器访问http://localhost:8088/index




阅读全文
1 0
原创粉丝点击