1

I have a simple Spring application:

Main class:

@SpringBootApplication
@EnableScheduling
public class SchedulerApplication {

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

And class for scheduled job

@Component
public class Executor {

    private static final Logger log = LoggerFactory.getLogger(Executor.class);
    private Integer jobCounter = 1;

    @Scheduled(fixedDelay = 1000)
    public void run() {
        log.info("Start task (" + jobCounter + ")");
        log.info("Stop task");
        jobCounter ++;
    }
}

This is 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>

    <groupId>ru.alexeyzhulin</groupId>
    <artifactId>scheduler</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>scheduler</name>
    <description>Task scheduler</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

That is my project structure

enter image description here

It works fine under the IDE (IntelliJ IDEA), but when I compiled this code to jar file and run:

java -jar scheduler.jar

I got a long stack of errors like this

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [ru.alexeyzhulin.SchedulerApplication]; nested exception is java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.f actories. If you are using a custom packaging, make sure that file is correct.

What have I missed?

Alex Zhulin
  • 1,239
  • 2
  • 22
  • 42

2 Answers2

0

Add the following element under your sprig boot maven plugin in pom.

<configuration>
  <fork>true</fork>
  <mainClass>Your-main-config-class</mainClass>
</configuration>
VHS
  • 9,534
  • 3
  • 19
  • 43
  • Sorry, but it seems that I didn't understand your answer. I did this kind of modification in my pom file: ` org.springframework.boot spring-boot-maven-plugin true ru.alexeyzhulin.SchedulerApplication ' But it doesn't work. Where am I wrong? – Alex Zhulin Jan 28 '17 at 09:48
0

It seems that your SpringBootApplication class located in a wrong place. It should be properly located. Usually it is in a root of your artifact package. For example:

ru.alexeyzhulin.scheduler
   ru.alexeyzhulin.scheduler.SchedulerApplication
   ru.alexeyzhulin.scheduler.Executor

or

ru.alexeyzhulin.scheduler
   ru.alexeyzhulin.scheduler.SchedulerApplication
ru.alexeyzhulin.scheduler.components
   ru.alexeyzhulin.scheduler.components.Executor 

And look at it: Failed to process import candidates for configuration class

Community
  • 1
  • 1
rvit34
  • 1,967
  • 3
  • 17
  • 33
  • I modifed my question where I mentioned about my project structure. It seem that my project structure looks like your first option. – Alex Zhulin Jan 28 '17 at 10:02
  • Ok. I see. What does your MANIFEST.MF contain inside? Usually SpringBoot creates this resource itself. Try to build project without it. ` – rvit34 Jan 28 '17 at 18:36