0

I use spring mvc with spring configuration (without xml). And it seems like IDEA doesn't go to controller code. Maybe somewhere path is incorrect so @RequestMapping doesn't work. But i can't understand where exactly. Here is my Controller

@Controller
public class MainController {

    @RequestMapping(value = "/" , method = RequestMethod.GET)
    public String home() {

        return "index";
    }
    @RequestMapping(value = "welcome", method = RequestMethod.GET)
    public String welcome(Model m){
        m.addAttribute("name","lol kkeke");
        return "index2";
    }
}

WebMvcConfig

@Configuration
@ComponentScan("com.chat")
@EnableWebMvc
public class WebMVCConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/scripts/**").addResourceLocations("/scripts/");
        registry.addResourceHandler("/styles/**").addResourceLocations("/styles/");
        registry.addResourceHandler("/images/**").addResourceLocations("/images/");
        registry.addResourceHandler("/fonts/**").addResourceLocations("/fonts/");
        registry.addResourceHandler("/pages/**").addResourceLocations("/views/");

    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();

    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/index.jsp");
    }

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();

        resolver.setPrefix("/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        return resolver;
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Artem K
  • 31
  • 10

1 Answers1

1

So.. I solved a problem. It was in Controller - path. My Idea automatically change path from com.chat.controller to c.c.controller. So i rebuild project structure to com.chat.controller.Controller.class; and com.chat.config.Configuration.class.

Also, i found the next article about similar trouble. May be it will help somebody! How do I map Spring MVC controller to a uri with and without trailing slash?

Artem K
  • 31
  • 10