java 依赖问题“SpringBootServletInitializer 无法解析为类型”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44485589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dependencies issue "SpringBootServletInitializer cannot be resolved to a type"
提问by Dima Maligin
I'm getting SpringBootServletInitializer cannot be resolved to a type
as far as I understand this is a dependencies issue.
我得到SpringBootServletInitializer cannot be resolved to a type
据我理解,这是一个依赖问题。
While I feel comfortable writing Java code, this is my firs Application using maven
and spring-boot
naturally I'm clueless.
虽然我觉得编写 Java 代码很舒服,但这是我第一个使用的应用程序maven
,spring-boot
自然而然我一无所知。
pom.xml:
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:
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);
}
}
I can see that the relevant jar
files are present in the Maven Dependencies
folder, and while import
'ing the needed class
'es I noticed that the package
'es are there but they are "empty"(meaning intellisense finds the packages but not the classes inside them).
我可以看到jar
文件Maven Dependencies
夹中存在相关文件,并且在查找import
所需class
的 es 时,我注意到package
es 在那里但它们是“空的”(意味着智能感知找到了包,但没有找到其中的类)。
What am I missing?
我错过了什么?
回答by Ajoe
I had the same issue.My solution is
我有同样的问题。我的解决方案是
instead of
代替
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
use
利用
import org.springframework.boot.web.support.SpringBootServletInitializer;
Also in pom
也在 pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
回答by afulz29
Don't do anything new just press Ctrl+Shift+oin your eclipse it will add correct import to your project
不要做任何新的东西只是按Ctrl+ Shift+o在Eclipse将正确导入添加到您的项目
回答by paulsm4
I encountered the same problem ... but I'm using Maven with Spring Boot 2.1.1.
我遇到了同样的问题……但我在 Spring Boot 2.1.1 中使用了 Maven。
So I needed to specify the correct parent ... ANDchange the import/class name:
所以我需要指定正确的父级......并更改导入/类名称:
pom.xml:
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
MyApp.java:
我的应用程序.java:
...
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);
}
...
回答by angel molina
I'm following the same course and I just set the pom like this:
我遵循相同的课程,我只是像这样设置 pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
And works fine
并且工作正常