如何解决Springboot 应用程序启动后报错
我编写了一个 springboot 应用程序,但它在运行方法执行之前出错。我通过调试观察到它进入 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)
解决方法
删除 "status":"success","postcode":"BR1","postcode_type":"outcode","url":"https:\/\/propertydata.co.uk\/draw?input=BR1","data":[
[
null,null,"3.5"
],[
null,"5.6"
],"6.3"
]
],"process_time":"0.26"
注释
我建议将带有 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...
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。