The application supports spring mvc + hibernate + maven + tomcat. There is one controller:
@Controller public class ControllerBookmarks { private BookmarksService bookmarksService; private static final Logger logger = LoggerFactory.getLogger(ControllerBookmarks.class); @Autowired @Qualifier("bookmarksService") public void setBookmarksService(BookmarksService bookmarksService) { this.bookmarksService = bookmarksService; } @RequestMapping(value = "/bookmarks", method = RequestMethod.GET) public String listBookmarks(Model model) { logger.info("Вызван: listBookmarks"); model.addAttribute("bookmark", new Bookmarks()); model.addAttribute("bookmarks", bookmarksService.listBookmarks()); return "bookmarks"; } And there is one jsp, her name - bookmarks
Here is the project structure.
- The application is deployed in tomcat with context -
/. Dispatcher servlet Springs handles any requests to the address -
/.If I launch the application this way, then everything works fine, the url is
localhost:8080/bookmarks. But I want to write@RequestMapping("/bm")above the controller. When I do this and contact the address -localhost:8080/bm/bookmarks. I don’t get my jsp That's what it says to me in error - Message - /bm/WEB-INF/view/bookmarks.jsp. Error code 404. Where I could not indicate something or missed, please tell me, at least approximately?
That's what I want to do, I wrote the request mappings and when I write such a URL in the browser - localhost:8080/bm/bookmarks . I get 404 and message, which I wrote above. It must process the listBookmarks and return the necessary jsp. I understand that this message - Message - /bm/WEB-INF/view/bookmarks.jsp is based on what I wrote @RequestMapping("/bm") above the controller and what the resolver finds in the folder with the view. But why does he build such a path and how can I not fix it
@Controller @RequestMapping("/bm") public class ControllerBookmarks { private BookmarksService bookmarksService; private static final Logger logger = LoggerFactory.getLogger(ControllerBookmarks.class); @Autowired @Qualifier("bookmarksService") public void setBookmarksService(BookmarksService bookmarksService) { this.bookmarksService = bookmarksService; } @RequestMapping(value = "/bookmarks", method = RequestMethod.GET) public String listBookmarks(Model model) { logger.info("Вызван: listBookmarks"); model.addAttribute("bookmark", new Bookmarks()); model.addAttribute("bookmarks", bookmarksService.listBookmarks()); return "bookmarks"; } 
/bmabove the controller, this part of the URL is substituted for each method. I will add the controller code to the end of the question as I write and this option does not work for me. - Maks Ohotnikov pm@RequestMappingin my project, it works as you expected. Looking for a mistake elsewhere. Try running the debugger and find out where the error occurs and what the exception is thrown. - Krychun Ivan pm