自定义starter测试时,自动导入失败,问题解决

1、创建starter项目

在通过创建xxx-spring-boot-starter项目,并依赖创建的xxx-spring-boot-starter-autoconfige项目,通过在xxx-spring-boot-starter-autoconfige项目中自定义xxxPropertiesxxxAutoConfiguration,以及依赖xxxProperties的业务类,并且在resourecs下创建META-INF/spring.factories ,配置好EnableAutoConfiguration路径

2、将创建好的两个项目进行打包

先将xxx-spring-boot-starter-autoconfige项目进行打包,通过maven的clean,install插件导入maven仓库,在将xxx-spring-boot-starter导入maven仓库

3、创建测试类并导入自定义的starter

导入后在使用@Autowired,自动导入我们在xxx-spring-boot-starter-autoconfige中定义的业务类失败,其实我们是已经导进去了,也能点进去,但是发现点进去后下不了源码,显示not found

4、解决方法

xxx-spring-boot-starter-autoconfige项目中修改maven 的插件

<plugin>
   <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.3.7.RELEASE</version>
    <configuration>
        <skip>true</skip>
        <mainClass>com.shuang.hello.XiaoshuangHelloSpringBootStarterAutoconfigureApplication</mainClass>
    </configuration>
    <executions>
        <execution>
            <id>repackage</id>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
           ```
           

猜你喜欢

转载自blog.csdn.net/weixin_46195957/article/details/120068904