Spring Boot&静态文件的Jetty目录索引

时间:2014-07-22 10:16:12

标签: java spring-mvc jetty spring-boot

我在嵌入式jetty服务器上运行一个简单的spring boot webapp,即主应用程序类:

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

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

我在其中一个自动配置的位置(/ static)中有一堆静态文件和目录,其中将提供静态内容。当我点击基本URI时,我希望能够查看静态内容的目录索引,以便我可以浏览它。

我已经读过包含jetty的容器,通常会附带一个默认的处理程序来公开它,但是我的应用程序只返回404,所以我假设通过spring-boot执行此操作需要一些额外的步骤。任何人都可以建议我需要做什么/我的理解是否正确?

1 个答案:

答案 0 :(得分:0)

不知何故,您必须将dirAllowed设置为true。这是在JettyEmbeddedServletContainerFactory

中完成的

查看addDefaultServlet

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

有一行holder.setInitParameter("dirAllowed", "false");

相关问题