Skip to content

Instantly share code, notes, and snippets.

@maggandalf
maggandalf / RootContext.java
Created June 20, 2011 09:06 — forked from anonymous/RootContext.java
RootContext Java based Spring Configuration
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 {
@maggandalf
maggandalf / WebAppInitializer.java
Created June 20, 2011 09:04 — forked from anonymous/WebAppInitializer.java
Java-based conatiner configuration with no web.xml.
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));
@maggandalf
maggandalf / web.xml
Created June 20, 2011 09:03 — forked from anonymous/web.xml
web.xml in Java-based container configuration.
<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>
@maggandalf
maggandalf / Controller.java
Created June 20, 2011 09:02 — forked from anonymous/Controller.java
Definition of MVC Controllers
@Configuration
public class ControllerConfig {
@Bean
public HomeController homeController() {
return new HomeController();
}
}
@maggandalf
maggandalf / ServletContext.java
Created June 20, 2011 09:00 — forked from anonymous/ServletContext.java
Servlet Context configuration using Java-based container configuration.
/**
* 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 {