Spring Boot: SpringBootServletInitializer 已弃用用

2022-08-31 14:16:39

我正在尝试通过遵循此将Spring Boot应用程序部署到JBoss。它运行良好,但SpringBootServletInitializer在1.4.0.RELEASE中被弃用。我应该使用哪一个?

Maven depedency

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

Java Code

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

答案 1

您正在使用此功能已弃用。相反:org.springframework.boot.context.web.SpringBootServletInitializer

org.springframework.boot.web.support.SpringBootServletInitializer

对于 SpringBoot 2.0

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


答案 2

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

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

推荐