依赖关系问题“ SpringBootServletInitializer无法解析为类型”

Dim*_*gin 6 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>
Run Code Online (Sandbox Code Playgroud)

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);
    }

}
Run Code Online (Sandbox Code Playgroud)

我可以看到jar文件Maven Dependencies夹中存在相关文件,并且在查找import所需class的es时,我注意到packagees在那里,但它们是“空的”(意味着intellisense会找到软件包,但找不到其中的类)。

我想念什么?

A A*_*A A 6

我有同样的问题我的解决方案是

代替

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
Run Code Online (Sandbox Code Playgroud)

使用

import org.springframework.boot.web.support.SpringBootServletInitializer;
Run Code Online (Sandbox Code Playgroud)

也在pom

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
Run Code Online (Sandbox Code Playgroud)

  • 现在(2.0.1-RELEASE)移至org.springframework.boot.web.servlet.support.SpringBootServletInitializer; (4认同)

小智 6

不要做任何新的东西只是按Ctrl+ Shift+ o在Eclipse将正确导入添加到您的项目


ang*_*ina 0

我正在遵循相同的课程,我只是像这样设置 pom:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
</parent>
Run Code Online (Sandbox Code Playgroud)

并且工作正常