I have the weirdest error ever. In my logs it validates I have created a mapping for "TrainingRequest"
018-10-23 21:58:43,900 [main] [INFO ] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/TrainingRequest],methods=[GET]}"
But when I try to go the page http://localhost:8080/WEB/TrainingRequest, I get a page 404, and the logs says the dispatcher is unable to find the mapping. It reads below as
2018-10-23 22:00:17,129 [http-nio-8080-exec-1] [DEBUG] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/TrainingRequest] 2018-10-23 22:00:17,132 [http-nio-8080-exec-1] [WARN ] o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB/TrainingRequest] in DispatcherServlet
http://localhost:8080/WEB/ works properly, so I doubt it is an issue of configuration. However, here are the snippets below. If you think the issue could be file structure, here is my github link
WebConfig.Java
@EnableWebMvc
@Configuration
@ComponentScan(basePackages = "com.project.LNUProject.config")
@Slf4j
public class WebConfig implements WebMvcConfigurer {
// == constants ==
public static final String RESOLVER_PREFIX = "/WEB-INF/view/";
public static final String RESOLVER_SUFFIX =".jsp";
// == bean methods
@Bean
public ViewResolver viewResolver() {
UrlBasedViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix(RESOLVER_PREFIX);
viewResolver.setSuffix(RESOLVER_SUFFIX);
return viewResolver;
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
log.info("registry add properly");
registry.addViewController("/").setViewName(ViewNames.HOME);
}
}
ConstantsController.java
@Controller
@Slf4j
public class ConstantsController {
// == handler methods ==
// http://localhost:8080/WEB/
@GetMapping("/")
public String home() {
log.info("Home template map");
return ViewNames.HOME;
}
}
RequestTraining.java
@Controller
@Slf4j
public class RequestTrainingController {
final String NAME = "TrainingRequest";
// == handler methods ==
// http://localhost:8080/WEB/TrainingRequest
@GetMapping(NAME)
public String TableView() {
log.info("Training VIEW being called");
return NAME;
}
@GetMapping(Mappings.HOME + NAME + Mappings.EDIT)
public String EditTableView() {
return NAME + Mappings.EDIT;
}
@GetMapping(Mappings.HOME + NAME + Mappings.DELETE)
public String DeleteTableView() {
return NAME + Mappings.DELETE;
}
@GetMapping(Mappings.HOME + NAME + Mappings.ADD)
public String AddTableView() {
return NAME + Mappings.ADD;
}
}
In your addViewController
method mapping for TrainingRequest
is missing
Do something like this
@Override
public void addViewControllers(ViewControllerRegistry registry) {
log.info("registry add properly");
registry.addViewController("/").setViewName(ViewNames.HOME);
registry.addViewController("/TrainingRequest").setViewName("TrainingRequest");
}