java - "The type org.springframework.web.WebApplicationInitializer cannot be resolved. It is indirectly referenced from required .class files"

标签 java spring-boot image-uploading

这是包含错误的文件..int 类它说错误“类型 org.springframework.web.WebApplicationInitializer 无法解析。它间接引用自 所需的 .class 文件 - SpringBootWebApplication 类型的层次结构不一致”

 package java.com;

        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 SpringBootWebApplication extends SpringBootServletInitializer {

            @Override
            protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
                return application.sources(SpringBootWebApplication.class);
            }

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

        }

这是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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>spring-boot-web-jsp</artifactId>
    <packaging>war</packaging>
    <name>Spring Boot Web JSP Example</name>
    <description>Spring Boot Web JSP Example</description>
    <version>1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!-- Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Web with Tomcat + Embed -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Need this to compile JSP -->
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- Optional, for bootstrap -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- Package as an executable jar/war -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

最佳答案

此处 Spring boot 应用程序正在扩展 SpringBootServletInitializer。如果我查看 SpringBootServletInitializer,它会实现 WebApplicationInitializer。 添加以下具有适当版本的依赖项,该版本将解析 SpringBootServletInitializer。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.0.8.RELEASE</version>
</dependency>

关于java - "The type org.springframework.web.WebApplicationInitializer cannot be resolved. It is indirectly referenced from required .class files",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43828774/

相关文章:

java - ZK MVVM 验证消息自动绑定(bind)?

java - Spring Boot Rest api csv下载不设置带扩展名的文件名

java - Spring Boot - 如何配置多个数据源

java - 如何在 Spring Boot 应用程序中将千分尺与 jmx 一起使用?

ios - 使用 AFnetworking 上传图像没有任何响应

使用 AjaxUpload 的 Python 图片上传

java - swing 组件的命名策略

java - 在 Eclipse (Kubuntu) 中安装 Akka for Java

java - 当我们向 GC 索取信息或要求清理 GC 时。它是对所有人进行清理还是对执行者进行清理?

javascript - 如何使用 AngularJS 下载并上传图像