Java Spring Boot:不推荐使用 SpringBootServletInitializer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38843015/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:41:07  来源:igfitidea点击:

Spring Boot: SpringBootServletInitializer is deprecated

javaspring-boot

提问by Aung Myat Hein

I am trying to deploy Spring Boot app to JBoss by following this. It worked well but SpringBootServletInitializeris deprecated in 1.4.0.RELEASE. Which one should I use?

我想通过以下春启动的应用程序部署到JBoss。它运行良好,但SpringBootServletInitializer在 1.4.0.RELEASE 中已弃用。我应该使用哪一种?

Maven depedency

Maven依赖

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

Java Code

Java代码

 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.web.SpringBootServletInitializer;

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

采纳答案by Aman Tuladhar

You are using org.springframework.boot.context.web.SpringBootServletInitializerthis is deprecated. Instead:

您正在使用org.springframework.boot.context.web.SpringBootServletInitializer它已被弃用。反而:

Use

org.springframework.boot.web.support.SpringBootServletInitializer

org.springframework.boot.web.support.SpringBootServletInitializer

For SpringBoot 2.0

对于 SpringBoot 2.0

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

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

回答by pradeep

You can try this - worked for me

你可以试试这个 - 为我工作

import org.springframework.boot.web.servlet.ServletContextInitializer;