M
M
Mark Ivanych2016-03-02 18:46:47
Spring
Mark Ivanych, 2016-03-02 18:46:47

How to configure the return of statics from the root of the site in spring mvc?

hello
web.xml

<servlet>
        <servlet-name>spring-web</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-web</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //registry.addResourceHandler("/builds/**") .addResourceLocations("/builds/").setCachePeriod(3600);
    registry.addResourceHandler("/**").addResourceLocations("/favicon.ico"); // Не работает!
}

At the root are files like robots.txt, favicon.ico and others that should be at the root, but they are not available.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
volyihin, 2016-03-10
@volyihin

Look at the code of the class from which you are inheriting what the addResourceHandlers method does or how the spring classes implement this method. By default, there are already added paths there, put your files there.

M
Mark Ivanych, 2016-03-10
@iormark

The problem was in the controller that intercepted requests

@RequestMapping(value = {
        "/{login:(?iu)[a-z_0-9]{5,64}}",
        "/{login:(?iu)[a-z_0-9]{5,64}}/{modifier:draft}"
}, method = RequestMethod.GET)

Made [[^.]a-z_0-9]to separate files from user pages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question