【问题标题】:Spring Boot: SpringBootServletInitializer is deprecatedSpring Boot:不推荐使用 SpringBootServletInitializer
【发布时间】:2016-12-15 01:03:04
【问题描述】:

我正在尝试按照this 将 Spring Boot 应用程序部署到 JBoss。它运行良好,但 SpringBootServletInitializer 在 1.4.0.RELEASE 中已弃用。我应该使用哪一个?

Maven 依赖

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

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

【问题讨论】:

  • 你能澄清你的问题吗,我看到在你的代码中你已经表明你使用了 @springBootApplication 而不是 SpringBootServletInitializer 。两者有什么关系?
  • 是的,你是对的。我的问题是不充分的。我已经更新了我的问题。

标签: java spring-boot


【解决方案1】:

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

使用

org.springframework.boot.web.support.SpringBootServletInitializer

对于 SpringBoot 2.0

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

【讨论】:

  • 对于spring boot 2.0.0,你需要使用“org.springframework.boot.web.servlet.support.SpringBootServletInitializer”
  • 为什么现在在支持包中?在新版本中是否有另一种方法可以创建 servlet?
【解决方案2】:

你可以试试这个——对我有用

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

【讨论】:

    猜你喜欢
    • 2020-02-13
    • 2017-02-16
    • 2020-10-08
    • 2021-09-20
    • 1970-01-01
    • 2020-11-06
    • 2017-07-15
    • 2019-09-05
    • 2020-11-18
    相关资源
    最近更新 更多