java - @ComponentScan 在 org.springframework.context.annotation 包中不存在
问题描述
我是新的 spring 框架,我正在练习 java Configuration(No XML)
在这个例子中,我需要@Configuration 和@ComponentScan(),它们应该存在于org.springframework.context.annotation
包中,但在这个包中@Configuration 可用但@ComponentScan 不可用。
每当我尝试使用 @ComponentScan 时,eclipse 都会建议我从org.springframework.config.java.plugin.context
无法正常工作的包中导入 @ComponentScan。
导入时
org.springframework.config.java.plugin.context.ComponentScan
我收到以下错误。
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'name' is defined
解决方案
您使用的 Spring 版本 3.0.1 是不存在 @ComponentScan 的旧版本。@ComponentScan 是在 3.1 中引入的,你可以在这里查看 spring 文档
据说它从 3.1 开始就存在
请尝试 3.1 或更高版本。
推荐阅读
- python-3.x - 如何修复:AttributeError:“字节”对象没有属性“插入”
- react-native - 为什么 react-router-native 不渲染我的组件?
- amazon-web-services - AWS EC2 专用主机资源共享
- r - MXNet-Caret 训练和优化
- django - 匹配查询不存在 搜索时出错
- hammer.js - domEvents: true 在 HammerJS 中的性能影响是什么?
- php - php cuRL 响应“无法转码数据流音频/flac -> 音频/x-float-array”-IBM Watson Speech to text API
- c++ - 读取和记录字符 ASCII 值到向量
- php - Post 和 Get 方法是 PHP 语言或 URL 的一部分吗
- php - PHP分页脚本 - 重复