springboot应用程序启动后出现错误

g2ieeal7  于 2021-07-23  发布在  Java
关注(0)|答案(2)|浏览(398)

我写了一个springboot应用程序,但它在执行run方法之前给出了错误。我通过debug观察到它进入了main方法,但之后它立即给出了错误。我检查了pom.xml文件,但没有发现依赖项有任何问题。
错误是: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z 你知道吗?
我的应用程序类是:

@Configuration
@SpringBootApplication
public class ProcessesApplication implements CommandLineRunner {    

private static Logger logger = LoggerFactory.getLogger(ProcessesApplication.class);

@Autowired
private BatchManager batchManager;

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

}

@Override
public void run(String... args) throws Exception {
    Integer threadCount = 5;        
    try {        
        if (args.length > 1 && args[1] != null && !args[1].trim().isEmpty()) {
            try {
                threadCount = Integer.valueOf(args[1].trim());
            } catch (Exception e) {
               e.getStackTrace(e));
            }
        }

        this.batchManager.setThreadCount(threadCount);
        this.batchManager.setProcessName("Process");
        this.batchManager.start();
    } catch (Exception e) {
        e.getStackTrace(e);
    }
}

}
我的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 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.2.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.App</groupId>
<artifactId>processes</artifactId>
<version>1.0.1</version>
<name>processes</name>
<description>data sending </description>
<properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>      
</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.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>       
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
        </plugin>
    </plugins>
</build>

日志文件:

Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:81)
at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:304)
at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:225)
at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:196)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.App.processes.ProcessesApplication.main(ProcessesApplication.java:39)
z0qdvdin

z0qdvdin1#

删除 @Configuration 注解

at0kjp5o

at0kjp5o2#

我建议把班级和学生分开 main() 其他类的函数。
基本上创建一个只有 main() 函数的内部和另一个类 CommandLineRunner .
例子:

@SpringBootApplication
@EnableAsync
public class SpringApp{

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

还有一个单独的班级 Runner :

@Component
public class ARunner implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception
    {
        // Your code...
    }
}

相关问题