美文网首页
spring boot 自定义属性自动提示

spring boot 自定义属性自动提示

作者: 小白_u767d | 来源:发表于2020-02-19 18:10 被阅读0次

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

相关文章

网友评论

      本文标题:spring boot 自定义属性自动提示

      本文链接:https://www.haomeiwen.com/subject/uyaafhtx.html