Spring XML bootstrap + config vs Spring Java bootstrap + config

Here, we, go..

XML

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
 
    <display-name>Spring Application</display-name>
 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/rootContext.xml</param-value>
    </context-param>
 
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
 
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/resource/*</url-pattern>
    </servlet-mapping>
 
    <servlet>
        <servlet-name>springDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servletContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>springDispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
 
</web-app>

rootContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
 
    <bean name="greetingServiceImpl" class="com.wrox.GreetingServiceImpl" />
 
</beans>

servletContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
 
    <mvc:annotation-driven />
 
    <bean name="helloController" class="com.wrox.HelloController">
        <property name="greetingService" ref="greetingServiceImpl" />
    </bean>
 
</beans>

Classes:
public interface GreetingService {
    public String getGreeting(String name);
}
 
public class GreetingServiceImpl implements GreetingService {
 
    @Override
    public String getGreeting(String name) {
        return "Hello, " + name + "!";
    }
 
}
  
@Controller
public class HelloController {
 
    private GreetingService greetingService;
 
    @ResponseBody
    @RequestMapping("/")
    public String helloWorld() {
        return "Hello, World!";
    }
 
    @ResponseBody
    @RequestMapping(value = "/", params = {"name"})
    public String helloName(@RequestParam("name") String name) {
        return this.greetingService.getGreeting(name);
    }
 
    public void setGreetingService(GreetingService greetingService) {
        this.greetingService = greetingService;
    }
 
}

Java

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
 
</web-app>

Classes
@SuppressWarnings("unused")
public class Bootstrap implements WebApplicationInitializer {
 
    @Override
    public void onStartup(ServletContext container) throws ServletException {
 
        container.getServletRegistration("default").addMapping("/resource/*");
 
        AnnotationConfigWebApplicationContext rootContext
                = new AnnotationConfigWebApplicationContext();
        rootContext.register(MyRootContextConfiguration.class);
        container.addListener(new ContextLoaderListener(rootContext));
 
        AnnotationConfigWebApplicationContext servletContext =
                new AnnotationConfigWebApplicationContext();
        servletContext.register(MyServletContextConfiguration.class);
 
 
        //This is for bootstrapping Spring:
        ServletRegistration.Dynamic dispatcher = container.addServlet(
                "springDispatcher", new DispatcherServlet(servletContext)
        );
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }
 
}
 
@Configuration
@ComponentScan(
        basePackages = "com.wrox.site",
        excludeFilters = @ComponentScan.Filter(Controller.class)
)
public class MyRootContextConfiguration {
}
 
@Configuration
@EnableWebMvc
@ComponentScan(
        basePackages = "com.wrox.site",
        useDefaultFilters = false,
        includeFilters = @ComponentScan.Filter(Controller.class)
)
public class MyServletContextConfiguration {
 
}