springboot配置文件自定义配置数据
程序员文章站
2022-05-01 23:49:56
...
先看源码
@ConfigurationProperties(
prefix = "spring.datasource"
)
public class DataSourceProperties implements BeanClassLoaderAware, InitializingBean {}
类似的springboot自动配置
public final class SpringProperties {
private static final String PROPERTIES_RESOURCE_LOCATION = "spring.properties";
private static final Log logger = LogFactory.getLog(SpringProperties.class);
private static final Properties localProperties = new Properties();
private SpringProperties() {
}
所以仿照着写一个实现自定义配置数据
yml中
db.page:
pageSize: 3
类中
/**
* @configuration 描述的对象为一个配置对象,可以由Spring对其管理
* @author DELL
*/
@Setter
@Getter
@Configuration
@ConfigurationProperties(
prefix = "db.page"
)
public class PageProperties{
private int pageSize;
}