Another way to bootstrap Spring in a Java Web Application

This example uses AbstractAnnotationConfigDispatcherServletInitializer.!

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
         version="3.0">
 
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/resource/*</url-pattern>
    </servlet-mapping>
</web-app>

MyWebAppInnit.java
package biz.tugay.springJuly18.config;
/* User: koray@tugay.biz Date: 18/07/15 Time: 15:09 */
 
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
 
@SuppressWarnings(value = "unused")
public class MyWebAppInnit extends AbstractAnnotationConfigDispatcherServletInitializer {
 
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{RootConfigClass.class};
    }
 
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{ServletConfigClass.class};
    }
 
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

RootConfigClass.java
package biz.tugay.springJuly18.config;
/* User: koray@tugay.biz Date: 18/07/15 Time: 15:10 */
 
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
 
@Configuration
@ComponentScan(basePackages = "biz.tugay.springJuly18.service")
public class RootConfigClass {
}

ServletConfig.java
package biz.tugay.springJuly18.config;
/* User: koray@tugay.biz Date: 18/07/15 Time: 15:10 */
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
 
@Configuration
@ComponentScan(basePackages = "biz.tugay.springJuly18.web")
public class ServletConfigClass {
 
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver =
                new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        resolver.setExposeContextBeansAsAttributes(true);
        return resolver;
    }
}