Upgrading to Spring 5: Remove DefaultAnnotationHandlerMapping

Lately, I've been working in upgrading one project from Spring 4 to Spring 5. And this "error" is one that I'm encounter during upgrade process:

java.lang.ClassNotFoundException: org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping

It's not an surprise since DefaultAnnotationHandlerMapping is already deprecated as of Spring 3.2, in favor of RequestMappingHandlerMapping. So removing this class in the next (major) version - Spring 5 is completely understandable.

So I removed these two lines from my xml:

<context:annotation-config />
    
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
                    

You can refer to old project poc-swagger-springmvc which is part of my previous article POC: Swagger - Spring MVC (And Swagger UI) and Action Report: poc-swagger-springmvc in my old blog. And check the upgraded version in spring-rest-examples.

Here the version in pom.xml before and after upgrade:

<properties>        
    ...
    <org.springframework.version>4.2.6.RELEASE</org.springframework.version>
    <org.springframework.security.version>3.2.5.RELEASE</org.springframework.security.version>
    ...
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>

    ...
</dependencies>
                    

And after upgrade:

...
<org.springframework.version>5.1.2.RELEASE</org.springframework.version>
<org.springframework.security.version>5.1.1.RELEASE</org.springframework.security.version>
...
                    

Next article Jetty Maven Plugin and REST Assured is wrote about upgrading Jetty Maven Plugin and REST Assured in same project.