java - 依赖问题 "SpringBootServletInitializer cannot be resolved to a type"

标签 java spring maven spring-boot

我得到 SpringBootServletInitializer cannot be resolved to a type 据我了解,这是一个依赖性问题。

虽然我觉得编写 Java 代码很舒服,但这是我第一个使用 mavenspring-boot 的应用程序,自然我一无所知。

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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>univers-web</artifactId>
    <packaging>war</packaging>

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

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

    <dependencies>
        <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>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

SpringBootApplication.java:

package com.thebyteguru.launcher;

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

public class SpringBootApplication extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootApplication.class);
    }

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

}

我可以看到相关的 jar 文件存在于 Maven Dependencies 文件夹中,同时 import 正在导入所需的 class'es 我注意到 package'es 在那里,但它们是“空的”(意味着 intellisense 找到包而不是其中的类)。

我错过了什么?

最佳答案

我遇到了同样的问题,我的解决方案是

代替

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

使用

import org.springframework.boot.web.support.SpringBootServletInitializer;

也在pom中

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

关于java - 依赖问题 "SpringBootServletInitializer cannot be resolved to a type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44485589/

相关文章:

java - Hibernate中的@Formula计算日期时间

java - 禁用 Hibernate 的递归获取

java - SpannerOptions 处的 Google Spanner NullPointerException

hibernate - @OrderBy导致org.hibernate.HibernateException : Unable to parse order-by fragment

java - 我如何在 android 中将字节数组转换为 long

java - CXF 中的拦截器不会按照添加到拦截器的顺序调用

java - 在内存中和自定义提供程序一起

spring - 由 : java. lang.IllegalArgumentException : Token (spring. cloud.vault.token 引起)不能为空 - Hashicorp Vault

java - Spring注释/记录Spring自定义事件的方法

java - JSF 如何在我的应用程序中显示 pom.xml 版本?