K
K
Knyashshsh2019-05-23 17:34:03
Java
Knyashshsh, 2019-05-23 17:34:03

Why is MvcConfig not working in Spring?

The code has been copied from the Spring docs and changed a bit. So, when registering resources, the response is always code 200 and the main page. I can not understand in which direction to dig?

package online.ghostriting.ghost.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String uploadPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**")
                .addResourceLocations("file:///D:/Fun/Java/ghostwriting/src/uploads/");
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
}

There was also this code, but it also returned just the main page of the site. I implemented it through the Controller (Everything works), but that's not the case.
public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }

Only the first time I paw the spring, where could something go wrong? Where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2019-05-23
Hasanly @azerphoenix

Hello!
Or maybe the problem is not in MVCConfig, but, for example, in Spring Security (if you have it connected?).
Maybe you're getting a 403 error and then redirecting to home (status 200) because of Spring Security.
What is written in the logs?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question