首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >依赖关系问题“无法将SpringBootServletInitializer解析为类型”

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

Stack Overflow用户
提问于 2017-06-11 23:35:05
回答 3查看 21.1K关注 0票数 7

据我所知,这是一个依赖问题,我正在使用SpringBootServletInitializer cannot be resolved to a type

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

pom.xml:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
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时,我注意到package在那里,但它们是“空的”(这意味着智能感知可以找到包,但不能找到包中的类)。

我错过了什么?

EN

回答 3

Stack Overflow用户

发布于 2017-08-09 22:06:09

我有相同的issue.My解决方案

而不是

代码语言:javascript
复制
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

使用

代码语言:javascript
复制
import org.springframework.boot.web.support.SpringBootServletInitializer;

也在pom中

代码语言:javascript
复制
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
票数 11
EN

Stack Overflow用户

发布于 2018-12-07 07:53:58

我也遇到了同样的问题...但我使用的是带有Spring Boot 2.1.1的Maven。

所以我需要指定正确的父对象...并更改导入/类名称:

pom.xml:

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
</parent>

MyApp.java:

代码语言:javascript
复制
...
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
// import org.springframework.boot.web.support.SpringBootServletInitializer;  // OBSOLETE
import org.springframework.boot.web.servlet.support.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);
    }
...
票数 2
EN

Stack Overflow用户

发布于 2017-08-01 13:56:51

我正在遵循相同的过程,我只是将pom设置为:

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
</parent>

并且工作正常

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44485589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档