【发布时间】:2014-04-21 23:26:40
【问题描述】:
我有 2 个项目。 一个是 DAL 项目,它使用 spring neo4j APIs 在 neo4j DB 上执行 CRUD 操作。该项目被打包为 jar 并包含在项目 #2 中。 项目 #2 是一个 Spring RESTful 服务项目,它使用 Spring Boot 打包并创建一个在嵌入式 tomcat 服务器上运行的可执行 jar。
当尝试运行 Spring boot 为我创建的可执行 jar 时,我不断收到此异常。 预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
根据我的阅读,如果我使用@ComponentScan,我可以提供注释目录以供查看。所以我给它提供了我的服务项目的基本目录。我给了它包含的 DAL.jar 的基本目录,但这里仍然没有运气是注释的样子。
从 cmets 中提取:
组件扫描声明
@ComponentScan({"com.foo.dal.*","com.foo.notification.*"})
堆栈跟踪:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushCommandsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.teradata.dal.example.PushRepository com.teradata.notification.rest.controller.PushCommandsController.repository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.teradata.dal.example.PushRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
更新:
基于@chrylis 的回答: 对@ComponenetScan 进行了更改
@ComponentScan({"com.teradata.notification","com.teradata.dal"})
跑到:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration' is defined
有关 DAL 项目和服务项目的更多详细信息:
DAL 项目:
服务项目:
【问题讨论】:
-
抱歉忘记了我正在使用的注释
-
@ComponentScan({"com.foo.dal.*","com.foo.notification.*"})
-
不要使用“谢谢”,请附上代码示例。以及抛出的异常。
-
预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
-
更多细节是好的,但总是像你的图像内容一样发布文本作为文本。图片难以阅读,无法搜索或复制以进行测试。
标签: java spring spring-mvc spring-boot