我一直在学习如何使用spring数据,我创建了一个非常简单的项目来测试它。文件夹结构和applicationcontext.xml如下所示:applicationcontext.xml and folder structure我得到的错误如下所示:console error output。我在我的类路径上有applicationContext并且声明了该类的bean,知道我的问题是什么吗?谢谢。
编辑:我已更新我的帖子,以显示主类和dao类,以及我的pom.xml内容(在这一点上,我想知道我是否需要包含另一个依赖... ...)main class dao (repository)
我想念您的应用程序日志中的以下行:
... o.s.b.f.xml.XmlBeanDefinitionReader:从类路径资源[applicationContext.xml]加载XML bean定义
所以我假设你的applicationContext.xml文件根本没有加载。
要么添加
@ImportResource("classpath:applicationContext.xml")
到您的应用程序类或添加
@Repository
您的UserRepository类的注释。
在我看来,如果可能的话,你应该避免混合使用Java和XML Spring配置。