views:

66

answers:

1

Is it possible to reuse the predefined controllers, like the SimpleFormController, with annotation configured spring mvc projects?

I downloaded a project that looks like what I want; however, the writer did not use the annotations that are predefined in Spring.

The controller of the downloaded project:

package net.sourceforge.sannotations.example2;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sourceforge.sannotations.annotation.Bean;
import net.sourceforge.sannotations.annotation.UrlMapping;

/**
 * User: Urubatan Date: 24/10/2006 Time: 08:49:09
 */
@Bean
@UrlMapping("/test")
public class ExampleController implements Controller {
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return new ModelAndView("example", "message", request.getParameter("tainted"));
    }
}

The project is downloaded from: http://sannotations.sourceforge.net/examples.html

+1  A: 

You can make them part of the spring-context faily easily - just annotate the @Bean annotation with @Component, and spring will detect it as a spring bean. Like:

 @Component
 public @interface Bean { .. }

For the URL-mapping, however, you might want to use a custom BeanPostProcessor to handle the value of the annotation.

Bozho
I see. So this is only possible with the customized annotations, right? There is no way to achieve this with the pre-defined annotations.
Winston Chen
No, you have to somehow instruct spring how to identify the custom annotations.
Bozho
Thank you very much. I now understand.
Winston Chen