0

我有一个 Spring MVC 应用程序,我在其中定义了一个静态资源处理程序,如下所示:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    if (resourceIdentifier != null) {
        registry.addResourceHandler("/admin-ui/**", "/admin-ui/").addResourceLocations(
                "file:" + resourceIdentifier.getResourcesLocation() + "/");
    }
}

(为简洁起见,我省略了HandlerInterceptor声明的其余部分。)

现在,该应用程序的主要入口点是:

https://foo.mysite.com/admin-ui/index.html

相反,我希望入口点是:

https://foo.mysite.com/admin-ui

目前,这会产生 404 错误。启用此功能的最简单方法是什么,最好使用ResourceHandlerRegistry?

4

1 回答 1

0

I added the following controller, which works partially:

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("admin-ui").setViewName("/admin-ui/index.html");
}

I needed to make a few other changes in my app since the other assets, e.g., the css, js, and template files were being accessed relative the index.html (i.e., with no admin-ui/ as part of the path). I needed to change this to being an absolute path to the server root, so for example in index.html:

<link href="css/bootstrap.min.css" rel="stylesheet">

became this:

<link href="/admin-ui/css/bootstrap.min.css" rel="stylesheet">

After doing this for all urls in the app, I can now access the app with or without the index.html.

于 2013-09-12T21:06:12.027 回答