executable assembly JAR. get error: No auto configuration classes found in META-INF/spring.factories

Hello everyone and thanks in advance for your help. I have the simplest application on IntelliJ IDEA 2020. When it runs in the IDE, everything works. As soon as I collect the JAR and try to execute it through "java -jar", I get an error

2020-04-25 13:52:52.746 INFO 6780 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on skif-app-web3 with PID 6780 (C:\WWW\IdeaProjects\demo\out\artifacts\demo_jar\demo.jar started by mashkov in C:\WWW\IdeaProjects\demo\out\artifacts\demo_jar) 2020-04-25 13:52:52.762 INFO 6780 --- [ main] com.example.demo.DemoApplication : The following profiles are active: dev 2020-04-25 13:52:53.090 ERROR 6780 --- [ main] o.s.boot.SpringApplication : Application run failed

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. at org.springframework.util.Assert.notEmpty(Assert.java:464) ~[demo.jar:na] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:173) ~[demo.jar:na] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:116) ~[demo.jar:na] at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:396) ~[demo.jar:na] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878) ~[demo.jar:na] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808) ~[demo.jar:na] at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779) ~[demo.jar:na] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192) ~[demo.jar:na] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319) ~[demo.jar:na] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[demo.jar:na] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[demo.jar:na] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[demo.jar:na] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[demo.jar:na] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[demo.jar:na] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[demo.jar:na] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [demo.jar:na] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [demo.jar:na] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [demo.jar:na] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [demo.jar:na] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [demo.jar:na] at com.example.demo.DemoApplication.main(DemoApplication.java:12) [demo.jar:na]

In the main module, the code is the same, that is, the autoconfigure.SpringBootApplication import is present

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class DemoApplication {

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

}

POM I left by default, as it was proposed

<?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 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>
        <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>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.6.RELEASE</version>
                <configuration>
                    <fork>true</fork>
                    <mainClass>com.example.demo.DemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Please, help. In other forums, the error is using the maven-assembly-plugin plugin, but I use one that should immediately give the correct result:spring-boot-maven-plugin


Ответы (1 шт):

Автор решения: Андрей

Решение было простым. Нужно было запускать сборку из окна жизненного цикла Maven

→ Ссылка