springboot 读取中文配置乱码  
   
所属分类 springboot
浏览量 1278
@PropertySource 指定编码为 UTF-8 ,默认为 iso8859-1
@PropertySource(value = "classpath:config.properties", ignoreResourceNotFound = true,encoding = "UTF-8" )
@RestController
public class ConfigEncodingController {	
	// application.properties
	@Value("${pet1}")
	private String pet1;
	
	// config.properties
	@Value("${pet2}")
	private String pet2;
	
	@Autowired
	Environment environment; 
	
	@RequestMapping("/configEncodingInfo")
	public Object info()throws Exception{
		Map map = new HashMap();		
		map.put("pet1", pet1);
		map.put("pet1_2", environment.getProperty("pet1"));
		map.put("pet2", pet2);
		return map;
	}		
}
完整代码
https://gitee.com/dyyx/springboothello/blob/master/src/main/java/demo/controller/ConfigEncodingController.java
 上一篇  
   
 下一篇  
 zookeeper配置参数 
 dubbo面试题 
 ZooKeeper面试题 
 jmx_prometheus_javaagent 使用 
 jmx_exporter JmxCollector 源码要点 
 jedis 获取 redis info 信息