Skip to content

Instantly share code, notes, and snippets.

@dhilst
Last active December 26, 2016 23:16
Show Gist options
  • Select an option

  • Save dhilst/448f190945189b1b0ab15770dd690595 to your computer and use it in GitHub Desktop.

Select an option

Save dhilst/448f190945189b1b0ab15770dd690595 to your computer and use it in GitHub Desktop.
# Spring configuration roadmap
* Create a Dynamic Web Project.
* Convert to maven.
* Add maven folder structure.
* Create Tomcat server.
* Add Tomcat server to project.
* Add org.springframework/spring-webmvc, javax.servlet/jstl, javax.servlet/javax.servlet-api dependecies to pom.xml.
* Create your package.
* Add extension of AbstractAnnotationConfigDispatcherServletInitializer class. This will create root & servlet application contexts.
* Implement getRootConfigClasses.
* Implement getServletConfigClasses. -> Classes annotated with @Configuration
* Implement getServletMappings. -> Servlet mapping (url-pattern at web.xml)
* Add configuration class.
* Add @Configuration, @EnableWebMvc, @ComponentScan(basePackage = "your.package") to configutation class.
* Create beans method at configuration class. Add @Bean to methods.
* Add getViewResolver method to configuration class. Instantiate InternalViewResourceViewResolver, add prefix and suffix. Return it.
* Create a controller. Return view name as String or ViewModel intance.
* Create views folder below WebContent/WEB-INF folder. This should match the returned view name above.
* Create <view-name>.jsp file.
* Add <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> to beggining of jsp file.
* Compile & Run.
# Request flow
Model -----------.
v
Request -> DispatcherServlet -> Handler Mapping (getServletMappings()) -> Controller -> ViewResolver -> View -> Response
# Spring-boot roadmap
* Run mvn archetype:generatex
* browse to maven folder
* add spring-boot parent
* add spring-boot-web dependency
* Add @RestController & @EnableAutoConfiguration to main
* Add some controller
* Add SpringApplication.run call to main
* run mvn spring-boot:run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment