我尝试过第三方bean添加到我的应用程序:NoSuchBeanDefinitionException:无型的排位豆的内部类
@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;
}
}
}
,我尝试自动装配这个是这样的:
@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)}
...
这应该不是问题。内部类支持。你的'startServer'方法是否被调用? –
您的配置正在加载?尝试选择一个虚拟bean(简单字符串)并查看是否从相同配置加载。 –
您的'ZMQ.Socket'在'startServer()'返回之前关闭。这是你的预期行为吗? –