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



我写了一个springboot应用程序,但是它在run方法执行之前给出了错误。我通过调试观察到它进入主方法,但之后它立即给出错误。我检查了pom.xml文件,但没有发现依赖关系有任何问题。

错误是:org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z

你知道吗?

我的app类是:

@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)

删除@Configuration注释

我建议将具有main()函数的类与其他类分开。

基本上创建一个类,里面只有main()函数,另一个类为CommandLineRunner

的例子:

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

Runner的单独Class:


@Component
public class ARunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception
{
// Your code...
}
}

相关内容

最新更新