自定义citycode.properties

#List properties
interceptor.servletPaths[0]=/WeChat/getContactId
interceptor.servletPaths[1]=/WeChat/getWeChatInfo
interceptor.servletPaths[2]=/WeChatSys/bound
interceptor.servletPaths[3]=/WeChatSys/code
interceptor.servletPaths[4]=/WeChatSys/query
interceptor.servletPaths[5]=/WeChatSys/updateBound

#Map Properties
interceptor.map.www=4201
interceptor.map.wuhan=4201
interceptor.map.tianjin=1200

读取properties:

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@Component
@PropertySource("classpath:citycode.properties")
@ConfigurationProperties(prefix = "interceptor")
public class CityCodeConfig {

    private List<String> servletPaths = new ArrayList<>();
    private Map<String, String> map = new HashMap<>();

}
blog-top-links={home:"/home"}
blog-list=1,2,3
@Component
@ConfigurationProperties
@PropertySource("properties文件路径")
public class BlogConfig {
    @Value("#{${blog-top-links}}")
    private Map<String, String> topLinks;
    @Value("#{'${blog-list}'.split(',')}")
    private List<Integer> list;

    ...
    省略get/set
    实际不能省略,否则虽然能启动不报错,但是无法获取到值
}
06-29 12:03