Spring Boot应用程序用于启动在web.xml中初始化servlet的应用程序。

10 浏览
0 Comments

Spring Boot应用程序用于启动在web.xml中初始化servlet的应用程序。

给定一个具有所有servlet映射和contextConfigLocations以加载spring beans的Web.xml。

如何使用SpringBoot应用程序加载此web.xml和相应的servlet和contextConfig?

Web.xml位于模块A中,调用应用程序B将模块A作为依赖项。

我的SpringBoot应用程序是:

@SpringBootApplication(scanBasePackages = {"com.test.package"})

@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})

public class StarterApp{

public static void main(String[] args) {

SpringApplication.run(StarterApp.class);

}

}

0
0 Comments

Spring Boot application to start application initializing servlets in web.xml问题的出现的原因是Spring Boot通常更喜欢基于注解的配置而不是基于XML的配置。默认情况下,Spring的web.xml文件通常位于src/main/webapp/WEB-INF目录中,并且Spring会自动加载它。

解决方法是使用基于注解的配置替代基于XML的配置。具体来说,可以使用Spring Boot提供的注解来配置servlet。这样可以避免使用web.xml文件,也更符合Spring Boot的设计原则。

更多详情请参考以下文章:

DispatcherServlet and web.xml in Spring Boot

0