spring boot 自定义属性自动提示
2020-02-19 本文已影响0人
小白_u767d
本文档只为在idea中自动提示自定义属性
1.配置属性类
@Component
@ConfigurationProperties(prefix = "spring.generator")
public class GeneratorProperty {
private String packageName ="com.guttv";
private String tablePrefix ="t_";
public String getDatabaseName() {
DataSourceProperties dataSourceProperties = SpringUtil.getBean(DataSourceProperties.class);
String databaseName=dataSourceProperties.getUrl();
return databaseName.substring(databaseName.lastIndexOf("/")+1,databaseName.indexOf("?"));
}
}
2.添加属性依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<!--可选依赖,项目导入时依赖不会传递-->
<optional>true</optional>
</dependency>
3.重新编译