Enabling Spring MVC Annotations while Preserving Existing XML Mappings

I am working on an application that was developed in Spring 2.5 using XML mappings. We recently upgraded our JARS to Spring 3.0, and also added some scanning components, trying to use Spring 3.0 with new MVC features, while preserving existing XML mappings.

However, if we added the following to enable mvc sping annotations

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- The following is the new XML configuration that we have tried to add -->
    <mvc:annotation-driven/>

    <!-- ... old XML mappings -->

</beans>

Then, Spring only searches for controllers annotated with @Controller, and our old ones It seems that XML mappings are ignored. The only solution to this problem is that we need to update all of our old XML mappings to be annotations (a difficult task) or is there some other solution?

XML- :

<bean id="loginController" class="com.app.controller.login.LoginController">
        <property name="loginService" ref="loginService"/>
</bean>

LoginController SimpleFormController. SimpleFormController, MultiActionController.

.

     <bean id="urlMapping"
          class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/login">loginController</prop>
...
+5
3

, , , , @RequestParam, , bean...

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

, , , , , .

, URL- XML , , , XML .

+3

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>

@RequestMapping , XML. API:

HandlerMapping beans DispatcherServlet , DefaultAnnotationHandlerMapping bean, HandlerMapping beans .

(, mvc: annotation-driven) Spring MVC XML . , namespace . , beans XML. , namespace ( " XML- " ), , , , .

, . , . , . ( ), .

+2

You tried

<context:annotation-config />
0
source

All Articles