Running TomCat in Eclipse. I type in the browser http://localhost:8080/springmvc/index.jsp and see " Hello World!".
But if I type http://localhost:8080/springmvc/hello, I see a 404 error
What am I doing wrong?
My Controller
@Controller
public class WebController {
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
My Config
@Configuration
@ComponentScan("ru.neutrino")
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
private final ApplicationContext applicationContext;
@Autowired
public WebConfig(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(applicationContext);
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
registry.viewResolver(resolver);
}
}