简体   繁体   English

在 Spring Boot 上关闭 DispatcherServlet

[英]Switch off DispatcherServlet on Spring Boot

How can I disable the DispatcherServlet on SpringBoot, even trying to disable it via servlet registration the uri mapping appears on the log:如何在 SpringBoot 上禁用 DispatcherServlet,甚至尝试通过 servlet 注册禁用它,uri映射出现在日志中:

@Bean
public ServletRegistrationBean servletRegistrationBean(final DispatcherServlet dispatcherServlet) {
    final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
    servletRegistrationBean.setEnabled(false);

    return servletRegistrationBean;
}

LOG日志

2015-06-10 10:39:57.552  INFO 7032 --- [           main] o.s.b.c.e.ServletRegistrationBean        : Servlet dispatcherServlet was not registered (disabled)
2015-06-10 10:39:57.553  INFO 7032 --- [           main] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]

Thanks any help!感谢任何帮助!

我将以下代码添加到我的主类中,并从日志中删除了 servlet。

@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })

From Spring boot docs here来自此处的Spring Boot 文档

Spring Boot wants to serve all content from the root of your application / down. Spring Boot 想要从应用程序的根目录/向下提供所有内容。 If you would rather map your own servlet to that URL you can do it, but of course you may lose some of the other Boot MVC features.如果您更愿意将您自己的 servlet 映射到该 URL,您可以这样做,但当然您可能会失去一些其他 Boot MVC 功能。 To add your own servlet and map it to the root resource just declare a @Bean of type Servlet and give it the special bean name dispatcherServlet (You can also create a bean of a different type with that name if you want to switch it off and not replace it).要添加您自己的 servlet 并将其映射到根资源,只需声明一个Servlet类型的@Bean并为其指定特殊的 bean 名称dispatcherServlet (如果您想将其关闭,也可以使用该名称创建不同类型的 bean 并不更换)。

If you exclude DispatcherServletAutoConfiguration.class , then you need to exclude ErrorMvcAutoConfiguration.class as well, or at least I did.如果您排除DispatcherServletAutoConfiguration.class ,那么您也需要排除ErrorMvcAutoConfiguration.class ,或者至少我做到了。

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class, ErrorMvcAutoConfiguration.class})
@EnableAspectJAutoProxy
public class CoreApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(CoreApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(CoreApplication.class);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法关闭Spring Boot安全配置 - failed to switch off the Spring Boot security configuration Spring Boot 应用程序卡在:Initializing Spring DispatcherServlet 'dispatcherServlet' - Spring Boot application stuck at: Initializing Spring DispatcherServlet 'dispatcherServlet' Spring Boot 中的 DispatcherServlet 和 web.xml - DispatcherServlet and web.xml in Spring Boot CharacterEncoding DispatcherServlet Spring Boot MVC响应jsp - CharacterEncoding DispatcherServlet Spring Boot MVC Response jsp 如何通过spring boot配置'dispatcherServlet'在启动时加载? - how to configure 'dispatcherServlet' load on startup by spring boot? 如何在Spring Boot应用程序中配置DispatcherServlet? - How to configure DispatcherServlet in a Spring Boot application? Spring 在 `FilterChainProxy` 和 `DispatcherServlet` 之间启动 1 分钟延迟 - Spring boot 1 minute delay between `FilterChainProxy` and `DispatcherServlet` Spring DispatcherServlet - Spring DispatcherServlet Spring Boot Web App错误:在名称为'dispatcherServlet'的DispatcherServlet中找不到带有URI [/]的HTTP请求的映射 - Spring Boot Web App Error: No mapping found for HTTP request with URI [/] in DispatcherServlet with name 'dispatcherServlet' Spring Boot,Java Config - 在DispatcherServlet中找不到带有URI [/ ...]的HTTP请求的映射,名称为“dispatcherServlet” - Spring Boot, Java Config - No mapping found for HTTP request with URI [/…] in DispatcherServlet with name 'dispatcherServlet'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM