1 回答
TA贡献1853条经验 获得超9个赞
@Configuration
@PropertySource("classpath:application.properties")
public class ConfigurationClass {
@Value("${app.value1}")
private String value1;
@Value("${app.value2}")
private String value2;
public String getValue1() {
return value1;
}
public String getValue2() {
return value2;
}
}
然后调用它
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
ApplicationContext c = SpringApplication.run(DemoApplication.class, args);
ConfigurationClass con = c.getBean(ConfigurationClass.class);
System.out.println(con.getValue1());
System.out.println(con.getValue2());
}
}
添加回答
举报