美文网首页
多模块下的ConfigurationProperties

多模块下的ConfigurationProperties

作者: 不二不二熊 | 来源:发表于2020-09-28 23:18 被阅读0次

    IDEA一直是我们比较中意的开发工具,因为在开发过程中它能做到许多智能提示,这大大提高了我们的生产效率。

    因此,如果我们想要在springboot的配置文件中自定义配置,并且能够关联到实体类并且能给出提示的话,除了必须的 @ConfigurationProperties 注解之外,我们还需要 spring-boot-configuration-processor maven依赖。

    在单个项目中,通常我们依赖了这两项,我们就能实现上述功能。然而,在多模块中,我发现尽管依赖了上述,IDAE仍然提示我 spring boot configuration annotation processor not configured

    作为强迫症晚期,我当然不能接受如此显眼的大红色报错,但是不管是springboot的官方文档还是stackoverflow,给出的解决办法仍然是这两种,我一度移动了依赖的位置去尝试,但这仍然无功而返。

    直到我在google中发现了这篇文章

    spring-boot-configuration-processor不适用于maven子模块项目

    文中给出了另外一种解决办法,就是添加plugin

               <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-configuration-processor</artifactId>
                                <version>2.3.3.RELEASE</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin> 
    

    终于,在添加以上的配置项目,重新编译后,我的子模块target下面自动生成了元数据,这次是可以点击进去了,问题由此迎刃而解。

    相关文章

      网友评论

          本文标题:多模块下的ConfigurationProperties

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