繁体   English   中英

Spring资源文件作为根

[英]Spring resource file as root

我有一个带有Spring java-config设置的单页webapp。 当前,我必须输入localhost/resources/index.html才能进入我的应用程序。 我想进行设置,这样我就可以输入localhost ,然后查看index.html页面。

这是我的WebConfig。 我不知道这是否是我需要弄乱的地方,但是我尝试添加registry.addResourceHandler("/").addResourceLocations("resources/index.html")但这没有用。 有任何想法吗? 我会以错误的方式处理吗?

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.example.web")
public class WebConfiguration extends WebMvcConfigurerAdapter
{

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        registry.addResourceHandler("/resources/**").addResourceLocations("resources/").setCachePeriod(31556926);
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

    ...
}

本地主机是您的本地服务器。 您不能启动应用程序。 每当您部署应用程序时,它都是本地主机上的上下文。 例如,您开发了一个名为HelloWorld的Web应用程序,则访问该应用程序的最小URL为http:// localhost :/ HelloWorld。为了默认为index.html,请将以下内容(如果尚不存在)添加到您的web.xml中

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

暂无
暂无

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

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