How to service external static HTML files in Spring Boot Embedded tomcat?

后端 未结 3 471
我在风中等你
我在风中等你 2021-01-12 03:38

I\'m new to Spring framework and Spring Boot.
I\'ve implemented a very simple RESTful Spring Boot web application.
You can see the nearly full source code in another

3条回答
  •  攒了一身酷
    2021-01-12 04:06

    I see from another of your questions that what you actually want is to be able to change the path to static resources in your application from the default values. Leaving aside the question of why you would want to do that, there are several possible answers.

    • One is that you can provide a normal Spring MVC @Bean of type WebMvcConfigurerAdapter and use the addResourceHandlers() method to add additional paths to static resources (see WebMvcAutoConfiguration for the defaults).
    • Another approach is to use the ConfigurableEmbeddedServletContainerFactory features to set the servlet context root path.
    • The full "nuclear option" for that is to provide a @Bean definition of type EmbeddedServletContainerFactory that set up the servlet container in the way you want it. If you use one of the existing concrete implementations they extend the Abstract* class that you already found, so they even have a setter for a property called documentRoot. You can also do a lot of common manipulations using a @Bean of type EmbeddedServletContainerCustomizer.

提交回复
热议问题