三、属性赋值
使用@value的写法
-
基本数据
-
SpEL #{}
-
${},取出配置文件中的值
- Bean
public class Book { @Value("数据结构") private String name; @Value("#{20-3}") private Double price; @Value("${writer}") private String writer; }
- 主配置类
@PropertySource(value={"classpath:/application.properties"})
@Configuration
public class MyConfigOfPropertyValues {
@Bean
public Book book(){
return new Book();
}
}
- application.properties
writer=jdy
也可以使用环境变量对象获取
ConfigurableEnvironment environment = context.getEnvironment();
String writer = environment.getProperty("writer");

浙公网安备 33010602011771号