方式一:
@Component @Data public class PropertyBean { @Value("${datasource.url}") private String url; @Value("${datasource.username}") private String userName; }
方式二:
@Component @Configuration @EnableAutoConfiguration public class PropertyBeanUtil { @Bean @ConfigurationProperties(prefix = "datasource") public PropertyBean propertyBean() { return new PropertyBean(); } }
配置文件:
datasource.username = admin datasource.url = /hello/world
时间: 2024-12-14 18:10:38