闲话少说 上来就是干
首先 弄个 Config 用于加载 自定义的配置文件'
@Configuration
@PropertySource(value = {"classpath:/mypro/dev.properties"},
ignoreResourceNotFound = true,encoding = "utf-8")
public class Proconfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
测试
@RestController
public class DemoController {
@Autowired
Environment env;
@GetMapping("test2")
public Map<String,Object> test2(){
//@PathVariable(value="id") String id
Map<String,Object> response= new HashMap<>();
response.put("id",2);
response.put("code",800);
response.put("msg","成功");
response.put("a",env.getProperty("a"));
response.put("b",env.getProperty("b"));
response.put("c",env.getProperty("c"));
response.put("mybatis.config-locations",env.getProperty("mybatis.config-locations"));
return response;
}
}
方式一 注入 Environment 用 getProperty("") 方法 去获取配置参数
网友评论