java - IntelliJ IDEA生成的Spring Boot项目Artifact导致错误

标签 java spring spring-boot

我正在使用 IntelliJ IDEA 开发 Spring Boot 项目,一切正常。我在 IntelliJ IDEA 中运行和测试应用程序没有问题。无论我将其配置为“应用程序”还是“Spring Boot”(从“运行/编辑配置”菜单),它都可以完美运行

但是,在我创建工件并尝试使用“java -jar AppName.jar”运行它后,出现了问题。它会抛出如下错误:

Could not find key 'spring.profiles.active' in any property source

Caused by: java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.

我提取了jar文件,spring.factories等文件确实在“META-INF”文件夹内。

我怀疑问题的原因是类路径。当我从 IntelliJ IDEA 中运行它时,我注意到它在“使用模块的类路径”中设置为模块。但是,在工件中,我无法正确设置。

您认为问题的原因是什么?我认为这是类(class)路径。如果不是的话,还能是什么?请帮忙!

我在这里提供我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>org.kurento.tutorial</groupId>
    <artifactId>kurento-tutorial</artifactId>
    <version>6.6.1-SNAPSHOT</version>
</parent>

<artifactId>WebRTCLiveApp</artifactId>
<packaging>jar</packaging>

<name>WebRTCLiveApp</name>
<description>Company Live App</description>

<licenses>
    <license>
        <name>Apache 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0</url>
        <distribution>repo</distribution>
    </license>
</licenses>

<organization>
    <name>Kurento</name>
    <url>http://www.kurento.org</url>
</organization>

<developers>
    <developer>
        <id>kurento.org</id>
        <name>-kurento.org Community</name>
        <organization>Kurento.org</organization>
        <organizationUrl>http://www.kurento.org</organizationUrl>
    </developer>
</developers>

<properties>

    <!-- Main class -->
    <start-class>com.company.live.webrtc.WebRTCLiveApp</start-class>

</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
    </dependency>

    <!-- Kurento -->
    <dependency>
        <groupId>org.kurento</groupId>
        <artifactId>kurento-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.kurento</groupId>
        <artifactId>kurento-utils-js</artifactId>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>webjars-locator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars.bower</groupId>
        <artifactId>bootstrap</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>draggabilly</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars.bower</groupId>
        <artifactId>demo-console</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars.bower</groupId>
        <artifactId>adapter.js</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars.bower</groupId>
        <artifactId>jquery</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars.bower</groupId>
        <artifactId>ekko-lightbox</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>${start-class}</mainClass>
                <layout>ZIP</layout>
                <classifier>exec</classifier>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
                <mainClass>${start-class}</mainClass>
            </configuration>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>banner.txt</include>
            </includes>
        </resource>
    </resources>
</build>

<profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <descriptor>src/assembly/bin.xml</descriptor>
                        <finalName>${project.artifactId}-${project.version}</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <configuration>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>no-assembly</id>
    </profile>
</profiles>

我搜索并尝试了其他示例/解决方案,但没有一个有效。

请帮忙!谢谢!

最佳答案

问题已解决。

在 IntelliJ Artifacts Create JAR from Modules 对话框中,我必须

  1. 选择“复制到输出目录并通过 list 链接”选项
  2. 确保 META-INF/MANIFEST.INF 文件设置为“src/main/resources”

现在一切正常(花了整个下午之后)。

关于java - IntelliJ IDEA生成的Spring Boot项目Artifact导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43520616/

相关文章:

java - 为什么mockito对象使用的方法不显示println?

java - 测试 Spring 的 @Async void-returning 方法

spring - 使用spring cloud stream Kinesis时如何设置PartitionKey

spring - 使用@WebFluxTest 测试 RouterFunction

spring-boot - Heroku SpringBoot ClassPathResource 获取 FileNotFoundException

java - Spring JDBC中如何组合多个参数源?

java - 如何抛出 IOException?

java - 如何在组件测试中动态排除spring boot配置类

java - 运行 jar 包应用程序时出现 Hibernate InvalidMappingException

spring - *.configuration.SecondaryDataSource 中方法 entityManagerFactory 的参数 0 需要找不到类型为 '*.EntityManagerFactoryBuilder' 的 bean