带有 maven-assembly-plugin 的 Fatjar - 在 META-INF/spring.factories 中找不到自动配置类

问题描述

我使用 maven-assembly-plugin 构建了一个简单的 Spring Boot 应用程序。

下面是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
            <descriptorRefs>
            <descriptorRef>
            jar-with-dependencies
            </descriptorRef>
            </descriptorRefs>
            <archive>
            <manifest>
            <mainClass>com.example.demo.DemoApplication</mainClass>
            </manifest>
            </archive>
            </configuration>
            <executions>
            <execution>
            <phase>package</phase>
            <goals>
            <goal>single</goal>
            </goals>
            </execution>
            </executions>
            </plugin>
        </plugins>
    </build>
</project>

我使用 maven clean install 生成 jar。

一旦我以 java -jar fatjar.jar 的身份运行 fatjar,我就会看到以下错误

meta-inf/spring.factories 中找不到自动配置类。如果 您使用的是自定义包装,请确保文件正确

我什至尝试添加带有 spring.factoriesmeta-inf 文件夹。没用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)