每個Spring 3文檔,The IoC container,@Named
註釋是一個等效於@Component
註釋的標準。@ Spring MVC中的註釋名稱
由於@Repository
,@Service
和@Controller
都是@Component
,我試圖用@Named
對所有的人都在我的Spring MVC應用程序。它工作正常。但我發現@Controller
的替代似乎有一個錯誤。在控制器類,原來,它是
@Controller
public class MyController{
...
}
它工作正常。當我改變@Controller
到@Named
@Named
public class MyController{
...
}
它失敗,出現錯誤:
"No mapping found for HTTP request with URI ...".
但如果我說@RequestMapping
以班級爲遵循
@Named
@RequestMapping
public class MyController{
...
}
預期它的工作。
對於@Repository
和@Service
,我可以簡單地將它們替換爲@Named
而沒有問題。但更換@Controller
需要額外的工作。在配置中有什麼我缺少的東西?
這是否意味着我可以放心地使用'@ Named'爲通用bean注入替換'@ Component',但是我仍然需要在Spring MVC特性中使用'@ Repository','@ Service'和'@ Controller'? –
@dino歡迎您。考慮接受這個答案,除非你想等待更多的答案和其他細節。 –