【问题标题】:Springboot app gives error after startingSpring Boot 应用程序启动后出现错误
【发布时间】:2021-05-18 07:08:39
【问题描述】:

我写了一个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)

【问题讨论】:

    标签: java spring spring-boot pom.xml


    【解决方案1】:

    移除@Configuration注解

    【讨论】:

    • 我添加了我的日志文件。
    • 我找到了解决方案。我的 Eclipse 包含 4 个不同的项目。其中一个给出了这个错误。在我的应用程序运行后我删除了这个项目。我的 pom.xml 包含那个 jar 但是当我想要import that project eclipse 给出了那个错误。实际上这是一个临时解决方案
    【解决方案2】:

    我建议将具有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...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2018-08-30
      • 1970-01-01
      • 2015-03-14
      • 2020-06-27
      • 2020-08-16
      • 1970-01-01
      • 2018-10-06
      • 2021-12-18
      相关资源
      最近更新 更多