接口配置文件自动映射到属性和实体类配置
- 创建配置类
public class DemoConfig{
···
···
}
- 对配置类添加@Component或者@Configration注解
- 使用@PropertySource注解指定配置文件位置
@PropertySource(value = "classpath:application.properties")
- 使用@Value注解获取配置文件中的相应配置
@Value("${demo.id}")
private String id;
- 添加设置器与访问器
- 通过注入Ioc对象Resource进来,才能在类中使用获取的配置文件值
@Autowired
private DemoConfig demoConfig;
@RequestMapping("configtest")
public String configTest(){
System.out.println(demoConfig.getid());
return demoConfig.getid();