{"id":20365035,"url":"https://github.com/h3ar7b3a7/springmvc","last_synced_at":"2026-05-10T00:48:39.356Z","repository":{"id":136744877,"uuid":"310530015","full_name":"H3AR7B3A7/SpringMVC","owner":"H3AR7B3A7","description":"After exploring Java Enterprise, Servlets \u0026 JSPs I felt ready to return back to Spring. I will explore what Spring MVC is all about, using a Spring servlet stack.","archived":false,"fork":false,"pushed_at":"2020-12-30T16:31:26.000Z","size":177,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T17:55:39.963Z","etag":null,"topics":["code-configurator","servlet-stack","spring-mvc","xml-configuration"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/H3AR7B3A7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-06T07:58:27.000Z","updated_at":"2020-12-30T16:31:28.000Z","dependencies_parsed_at":"2023-07-14T12:45:44.873Z","dependency_job_id":null,"html_url":"https://github.com/H3AR7B3A7/SpringMVC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H3AR7B3A7%2FSpringMVC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H3AR7B3A7%2FSpringMVC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H3AR7B3A7%2FSpringMVC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/H3AR7B3A7%2FSpringMVC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/H3AR7B3A7","download_url":"https://codeload.github.com/H3AR7B3A7/SpringMVC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241904719,"owners_count":20040021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-configurator","servlet-stack","spring-mvc","xml-configuration"],"created_at":"2024-11-15T00:15:04.319Z","updated_at":"2026-05-10T00:48:34.306Z","avatar_url":"https://github.com/H3AR7B3A7.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring web MVC\nAfter exploring Java Enterprise, Servlets \u0026 JSPs I felt ready to return to Spring and dive deeper into what Spring MVC is all about.\n\n### 'WAR'ning\nThis project goes against the principle of:\n\n    Make JAR, not WAR!\n                            -- Josh Long\n\nHowever, we will learn a lot about the inner workings of Spring. Also, there might be older projects we need to work on depending on this\nmonolithic type of packaging. (Or projects that for some reason need to save on web space, or depend on some other advantages of .war.)\n\n## Setup\nWe don't start this project with the Spring initializr though, but use the Maven 'archetype-web-app' option under Maven projects.\nWe could also just make a maven project and enable web application support. In IntelliJ we navigate to:\n'File -\u003e Project Structure -\u003e Modules'. There, select your web facet and click the plus button.) \nFrom what I understand, Spring hides some older project structure from the user, but to start off this project we will need access to the web.xml\nin the \"webapp \u003e WEB-INF\" - file structure. It is where we can set up and configure our connections to the 'invisible' dispatcher servlet,\nthe front-controller that has been doing all the hard work in our Spring projects without taking any credit.  \nBe sure to check the [POM](https://github.com/H3AR7B3A7/SpringMVC/blob/master/pom.xml) to see common dependencies we will want to add to our project.\nWhen using the Spring Initializr, it includes some of these dependencies already.\n\n## Dispatcher Servlet\nAs its name suggests, it is a central dispatcher for HTTP request handlers/controllers, e.g. for web UI controllers or HTTP-based remote service exporters.\nThe dispatcher servlet dispatches requests and responses to registered handlers for processing, providing convenient mapping and exception handling facilities.  \n\u003cbr\u003e\n\u003cimg width=\"500\" src=\"https://raw.githubusercontent.com/H3AR7B3A7/SpringMVC/master/front-controller.png\" alt=\"fc\"\u003e\u003cbr\u003e\n\u003cimg width=\"500\" src=\"https://raw.githubusercontent.com/H3AR7B3A7/SpringMVC/master/dispatcher-servlet.png\" alt=\"ds\"\u003e\n\n## XML or JavaConfig\nWe started off with a full XML-based configuration of the web application and the dispatcher servlet. Then we discarded the 'web.xml'\nand switched to using the annotated class 'MyWebInitializer'. After that we also changed out the -servlet.xml for the 'MyConfig' class.  \n[Here](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/WebApplicationInitializer.html)\nwe can find more information on how to set up either an XML-based configuration, a code-based one or even a hybrid.\n\n### View Resolver\nBecause all requests go through our dispatcher servlet we can also add a prefix and suffix to our views here.\nIf we ever change the view layer we would just need to change the suffix in one location.  \nJava Config:\n\n    @Bean\n        public InternalResourceViewResolver viewResolver(){\n    \n            InternalResourceViewResolver vr = new InternalResourceViewResolver();\n            vr.setPrefix(\"/WEB-INF/\");\n            vr.setSuffix(\".jsp\");\n    \n            return vr;\n        }\n        \nXml:\n\n    \u003cbean id=\"viewResolver\"\n          class=\"org.springframework.web.servlet.view.UrlBasedViewResolver\"\u003e\n        \u003cproperty name=\"viewClass\" value=\"org.springframework.web.servlet.view.JstlView\"/\u003e\n        \u003cproperty name=\"prefix\" value=\"/WEB-INF/jsp/\"/\u003e\n        \u003cproperty name=\"suffix\" value=\".jsp\"/\u003e\n    \u003c/bean\u003e\n\nIt is also possible to mix or chain, more on this [here](https://docs.spring.io/spring-framework/docs/3.0.0.M3/spring-framework-reference/html/ch16s05.html).\n\n## Error handling\nBecause we are not using spring boot, but are rather augmenting a Java web application with Spring features we would actually need web.xml in this case.\nThere is no Java Config equivalent for:  \n\n    \u003cerror-page\u003e\n            \u003clocation\u003e/error\u003c/location\u003e\n    \u003c/error-page\u003e\n    \nIn this [example](https://www.baeldung.com/servlet-exceptions) we can see how to fetch the error message along with the status code and exception type.\n\n## More ...\nWe will continue exploring The Spring Servlet Stack in two separate repositories to avoid confusion.  \nThese repositories can be found here:\n- [XML-based](https://github.com/H3AR7B3A7/SpringServletStackXml)\n- [Code-based](https://github.com/H3AR7B3A7/SpringServletStackCode)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh3ar7b3a7%2Fspringmvc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh3ar7b3a7%2Fspringmvc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh3ar7b3a7%2Fspringmvc/lists"}