gpt4 book ai didi

java - 线程异常 "main"java.lang.IllegalArgumentException : Cannot instantiate interface org. springframework.context.ApplicationContextInitializer

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:37 27 4
gpt4 key购买 nike

我遇到了以下错误:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:414) at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394) at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:385) at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:261) at org.springframework.boot.SpringApplication.(SpringApplication.java:237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)

我的主要方法是

package proj1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebApplication.class);
}

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

我的pom.xml是

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.webapp</groupId>
<artifactId>proj1</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
<version>0.0.1-SNAPSHOT</version>
<name>proj1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

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

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>proj1</finalName>
</build>
</project>

最佳答案

我最近遇到了这个问题。我正在通过一个 bat 文件运行一个可执行 jar。我的可执行 jar 已经包含 pom.xml 中提到的版本所需的所有 spring boot jar。但是错误地我也在 bat 文件中定义了 spring-boot 库(其他版本)的类路径。当我删除那个类路径条目时,这个特定问题就消失了,因为它只使用了 pom 文件中提到的 spring boot jar。我认为这个问题的出现是因为 spring jar 的版本冲突。如果我错了,请纠正我。谢谢。

关于java - 线程异常 "main"java.lang.IllegalArgumentException : Cannot instantiate interface org. springframework.context.ApplicationContextInitializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39944244/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com