本文档只为在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.重新编译
网友评论