java -jar demo.jar --server.port=9000
java -jar demo.jar --spring.application.json='{"foo":"bar"}'
@RestController
@RequestMapping("/task")
public class TaskController {
@Value("${connection.remoteAddress}") private String address;
@RequestMapping(value = {"/",""})
public String hellTask(@Value("${connection.username}")String name){
return "hello task !!";
}
}
@RestController
@RequestMapping("/task")
public class TaskController {
@Autowired Environment ev ;
@Value("${connection.remoteAddress}") private String address;
@RequestMapping(value = {"/",""})
public String hellTask(@Value("${connection.username}")String name){
String password = ev.getProperty("connection.password");
return "hello task !!";
}
}
@Component
public class SystemConfig {
private static Properties props ;
public SystemConfig(){
try {
Resource resource = new ClassPathResource("/application.properties");//
props = PropertiesLoaderUtils.loadProperties(resource);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 获取属性
* @param key
* @return
*/
public static String getProperty(String key){
return props == null ? null : props.getProperty(key);
}
/**
* 获取属性
* @param key 属性key
* @param defaultValue 属性value
* @return
*/
public static String getProperty(String key,String defaultValue){
return props == null ? null : props.getProperty(key, defaultValue);
}
/**
* 获取properyies属性
* @return
*/
public static Properties getProperties(){
return props;
}
}
//用的话,就直接这样子
String value = SystemConfig.getProperty("key");
myapp.name=spring
myapp.desc=${myapp.name} nice
my.secret=${random.value}
my.number=${random.int}
my.bignumber=${random.long}
my.number.less.than.ten=${random.int(10)}
my.number.in.range=${random.int[1024,65536]}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有