java - 应用程序启动失败 - 无法处理配置类的导入候选

标签 java spring spring-boot

当我尝试运行时,我在堆栈跟踪中收到此错误:

java -jar spring-boot-starter-web.jar

从我的 Spring Boot 应用程序 jar 构建的命令行中。我不确定是什么导致了这个错误。我让 IntelliJ 来构建项目。

[main] ERROR org.springframework.boot.SpringApplication - Application startup failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [app.ContactRunner]; nested exception is 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.

作为引用,ContactRunner 类只是:

@SpringBootApplication
public class ContactRunner {

  public static void main(String[] args) throws Exception {
    SpringApplication.run(ContactRunner.class, args);
  }
}

spring-boot-starter-parent 位于 pom.xml 以及 spring-boot-maven-plugin 中code> 因为其他有类似问题的人已经解决了他们的问题。我不明白发生了什么事。这是我的完整 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <!-- Output to jar format -->
    <packaging>jar</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starters</artifactId>
        <version>1.5.7.RELEASE</version>
    </parent>
    <artifactId>NameProject</artifactId>
    <name>Spring Boot Web Starter</name>
    <description>Starter for building web, including RESTful, applications using Spring
        MVC. Uses Tomcat as the default embedded container
    </description>
    <url>http://projects.spring.io/spring-boot/</url>
    <organization>
        <name>Pivotal Software, Inc.</name>
        <url>http://www.spring.io</url>
    </organization>
    <properties>
        <main.basedir>${basedir}/../..</main.basedir>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.4.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
       <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <!-- JPA Data (for using Repositories, Entities, Hibernate, etc...) -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- Use MySQL Connector-J -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.5.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.194</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>spring-boot</classifier>
                                <mainClass>
                                    app.ContactRunner
                                </mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

我还尝试使用 mvn clean package 构建项目,但它失败了,因为我似乎无法删除重复的依赖项,因为您可能会在这个问题中看到我的问题,所以这是尝试另一条路线。

有什么想法吗?该应用程序在 IntelliJ 中运行良好,但在 jar 中则无法运行。

最佳答案

我认为你应该在父标签中使用spring-boot-starter-parent。并且应该删除整个 dependencyManagement block 。

关于java - 应用程序启动失败 - 无法处理配置类的导入候选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46713195/

相关文章:

java - Curator 与 Zookeeper 服务发现连接被强制关闭

java - JPA CriteriaBuilder 子查询多选

java - 根据Java应用程序,SQLite数据库不存在

java - Spring 启动 hibernate 配置

java - 没有重定向的 Spring Security

java - 使用 groupBy 进行 Flux 并行串行执行

Spring - 如何测试具有 ApplicationEventPublisher 依赖关系的 Controller ?

spring-boot - Thymeleaf URL 语法很困惑

mysql - Liquibase 不在 MySQL/MariaDB 上执行 SQL,而是在 Spring Boot 中执行 H2

java - Spring Security 和 Oauth2 的误解