Dependencies issue “SpringBootServletInitializer cannot be resolved to a type”

后端 未结 4 2040
暗喜
暗喜 2021-01-12 18:11

I\'m getting SpringBootServletInitializer cannot be resolved to a type as far as I understand this is a dependencies issue.

While I feel comfortable wri

相关标签:
4条回答
  • 2021-01-12 18:27

    I encountered the same problem ... but I'm using Maven with Spring Boot 2.1.1.

    So I needed to specify the correct parent ... AND change the import/class name:

    pom.xml:

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

    MyApp.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);
        }
    ...
    
    0 讨论(0)
  • 2021-01-12 18:36

    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

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
    </parent>
    
    0 讨论(0)
  • 2021-01-12 18:46

    Don't do anything new just press Ctrl+Shift+o in your eclipse it will add correct import to your project

    0 讨论(0)
  • 2021-01-12 18:48

    I'm following the same course and I just set the pom like this:

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

    And works fine

    0 讨论(0)
提交回复
热议问题