作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试将第三方 bean 添加到我的应用程序中:
@Configuration
@ComponentScan(...)
public class ApplicationConfiguration {
@Bean(name = "mqSocket")
public ZMQ.Socket startServer() {
try (ZMQ.Context ctx = ZMQ.context(1);
ZMQ.Socket publisher = ctx.socket(ZMQ.PUB)) {
publisher.bind("tcp://*:5556");
return publisher;
}
}
}
我尝试像这样 Autowiring :
@RestController
public class MyRestController {
@Autowired
private ZMQ.Socket mqSocket;
但它打印以下内容:
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myRestController': Unsatisfied dependency expressed through field 'mqSocket'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.zeromq.ZMQ$Socket' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.zeromq.ZMQ$Socket' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
...
最佳答案
您应该添加 @Import
annotation在您的应用程序类中。
例如:
@Import(ApplicationConfiguration.class)
public class Application {
}
注:参见@M.Prokhorov 评论,ZMQ.Socket
由 try-with-resource 语句关闭
关于java - NoSuchBeanDefinitionException : No qualifying bean of type for inner class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43205347/
我是一名优秀的程序员,十分优秀!