2010-01-07 21 views
2

是否可以重新使用預定義的控制器,如SimpleFormController和註釋配置的spring mvc項目?是否可以在Spring註解配置的mvc項目中重用預定義的控制器?

我下載了一個看起來像我想要的項目;但是,作者並未使用Spring中預定義的註釋。

下載項目的控制器:

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")); 
    } 
} 

該項目從SourceForge

回答

2

下載的你可以讓他們彈簧上下文的一部分faily容易 - 只需註釋@Bean批註與@Component,和春天會發現它是春天的豆子。像:

@Component 
public @interface Bean { .. } 

對於URL映射,但是,您可能需要使用自定義BeanPostProcessor處理註釋的價值。

+0

我明白了。所以這隻適用於定製的註釋,對吧?使用預定義的註釋無法實現此目的。 – 2010-01-07 07:26:03

+0

不,你必須以某種方式指示春天如何識別自定義註釋。 – Bozho 2010-01-07 07:30:00

+0

非常感謝。我現在明白了。 – 2010-01-07 07:38:23

相關問題