只是一個簡單的問題。 @RequestMapping
僅適用於@Controller
類。我試圖用@RequestMapping
在我的應用程序@Component
豆地圖及其總是拋出noHandlerFound沒有映射發現HTTP請求的URI與
@RequestMapping for @Component Bean
2
A
回答
4
完全正確,你只能在@Controller
註釋類使用@RequestMapping
。從@Controller
類的javadoc:
基本控制器接口,代表接收就像的HttpServlet [...]
此外,@Controller
延伸 HttpServletRequest和HttpServletResponse的實例的組件@Component
bean,javadoc:
[@Component]指示註釋類是一個「組件」。當使用基於註釋的配置和類路徑掃描時,這些類被認爲是自動檢測的候選對象。
換句話說,一個@Component
(及其子註釋@Controller
)是什麼使一個類的Spring bean,而只用@RequestMapping
和其他HTTP相關的操作@Controller
註釋交易。
有關於刻板印標在春季reference documentation的詳細信息。
相關問題
- 1. Spring @Component中注入vaadin @UIScope bean @Component
- 2. Angular 2 Observable for custom component
- 3. 儘管@Component和@Bean沒有找到類的bean
- 4. 對於同一個Bean類@Component和@Named
- 5. 添加帶註解的bean定義的requestmapping註釋
- 6. Property for Place/Bean Refs
- 7. Spring @Component @Autowired
- 8. Spring RequestMapping 404錯誤
- 9. SpringBoot - @RequestMapping(name =「/ home」) - @RequestMapping(value =「/ home」)
- 10. Junit for Bean定義類
- 11. i18n與Spring MVC,跳過RequestMapping
- 12. Spring Component被掃描的bean無法訪問
- 13. 使用@Component進行bean拋出錯誤。 NoSuchBeanDefinitionException
- 14. 使用@Component和@Autowired時的Spring bean原始屬性?
- 15. 切入點到Spring @RequestMapping
- 16. Kotlin NoClassDefFoundError with spring @RequestMapping方法
- 17. Spring的@RequestMapping內部構造
- 18. 從RequestMapping
- 19. Spring @RequestMapping
- 20. Spring MVC RequestMapping混淆
- 21. Default RequestMapping不會被調用
- 22. Spring MVC的@RequestMapping動態值
- 23. Spring @RequestMapping,404錯誤
- 24. 春天@Component有什麼用?
- 25. WPF pack:/ [assemblyName]; component/... vs pack:// application:,,,/[assemblyName]; component/...?
- 26. CrudRepository刪除不允許@RequestMapping
- 27. @RequestMapping錯誤的RenderRequest
- 28. @RequestMapping(Accept)或ResponseEntity
- 29. RequestMapping in xml
- 30. Spring RequestMapping頭疼