This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mytld.mycompany.myapp.config; | |
import org.springframework.context.annotation.Configuration; | |
/** | |
* Root Context: defines shared resources visible to all other web components. | |
*/ | |
@Configuration | |
public class RootContextConfig { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebAppInitializer implements WebApplicationInitializer { | |
public void onStartup(ServletContext container) throws ServletException { | |
// Create the 'root' Spring application context | |
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); | |
rootContext.register(RootContextConfig.class); | |
// Manage the lifecycle of the root application context | |
container.addListener(new ContextLoaderListener(rootContext)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> | |
<context-param> | |
<param-name>contextClass</param-name> | |
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext | |
</param-value> | |
</context-param> | |
<context-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value>mytld.mycompany.myapp.config.RootContextConfig</param-value> | |
</context-param> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class ControllerConfig { | |
@Bean | |
public HomeController homeController() { | |
return new HomeController(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* DispatcherServlet Context: defines this servlet's request-processing infrastructure | |
*/ | |
@Configuration | |
//Enables the Spring MVC @Controller programming model | |
@EnableWebMvc | |
//Imports user-defined @Controller beans that process client requests. | |
@Import({Controller.class}) | |
public class ServletContextConfig extends WebMvcConfigurerAdapter { |