简体   繁体   English

Spring资源文件作为根

[英]Spring resource file as root

I have a single-page webapp with a spring java-config setup. 我有一个带有Spring java-config设置的单页webapp。 Currently, I have to enter localhost/resources/index.html to get to my app. 当前,我必须输入localhost/resources/index.html才能进入我的应用程序。 I would like to set it up so I can just enter localhost and then see the index.html page. 我想进行设置,这样我就可以输入localhost ,然后查看index.html页面。

This is my WebConfig. 这是我的WebConfig。 I don't know if this is where I need to be messing with stuff but I tried adding registry.addResourceHandler("/").addResourceLocations("resources/index.html") but that didn't work. 我不知道这是否是我需要弄乱的地方,但是我尝试添加registry.addResourceHandler("/").addResourceLocations("resources/index.html")但这没有用。 Any ideas? 有任何想法吗? Am I going about this the wrong way? 我会以错误的方式处理吗?

@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);
    }

    ...
}

localhost is your local server. 本地主机是您的本地服务器。 You cannot have bring up your app. 您不能启动应用程序。 Whenever you deploy your app it is a context on your localhost. 每当您部署应用程序时,它都是本地主机上的上下文。 eg you developed a web app with the name HelloWorld then your minimum URL to reach the app would be http://localhost :/HelloWorld In order to default to index.html add the following, if not already present, to your web.xml 例如,您开发了一个名为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