简体   繁体   中英

Spring Boot & Jetty Directory Index of Static Files

I have a simple spring boot webapp running on an embedded jetty server, ie the main application class:

@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties
@ComponentScan
public class SampleActuatorApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleActuatorApplication.class, args);
    }
}

I have a bunch of static files and directories in one of the auto-configured locations (/static) where static content will be served from. When I hit the base URI I want to be able to view a directory index of the static content so that I can browse through it.

I have read containers including jetty usually come with a default handler that will expose this, however my app just returns 404 so I assume there is some additional steps needed when doing this via spring-boot. Can anyone suggest what I need to do / is my understanding correct?

Somehow you'll have to set the dirAllowed to true. This is done in JettyEmbeddedServletContainerFactory

Take a look at addDefaultServlet

https://github.com/spring-projects/spring-boot/blob/master/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java

There is a line holder.setInitParameter("dirAllowed", "false");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM