@Scope停止注入类
我有以下课程:
@Component
@Qualifier("delegator")
@Scope(value = "simpleThreadScope", proxyMode = ScopedProxyMode.INTERFACES)
public class AsyncDelegator implements IAsyncDelegator {
....
}
以下控制器中使用的是:
@Controller
@RequestMapping("/*")
public class C2GWebController extends AbstractDeferredResultController {
@Autowired
@Qualifier("delegator")
IAsyncDelegator delegator;
....
}
但是,当在我们的开发机器上运行时,它会出现以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.company.async.IAsyncDelegator] 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), @org.springframework.beans.factory.annotation.Qualifier(value=delegator)}
即使使用以下配置扫描bean:
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.AUTODETECT)
@ComponentScan("com.company")
@EnableAsync
@RequestMapping
@EnableWebMvc
public class Config implements BeanFactoryAware {
....
}
开发机器是:
Server version: Apache Tomcat/7.0.42
Server built: Aug 4 2014 03:06:35
Server number: 7.0.42.0
OS Name: Linux
OS Version: 3.10.0-123.el7.x86_64
Architecture: amd64
JVM Version: 1.7.0_65-mockbuild_2014_07_14_06_04-b00
JVM Vendor: Oracle Corporation
这是运行CentOS 7
我已经看过this post但是该类正在控制器中通过界面引用。我建议这是由于操作系统配置,但这是一个相同的配置,正在部署到几台机器(通过Chef / Vagrant)。
软件中似乎有一些未被指定的东西会导致这种情况无效,但我无法解决它的问题。
此代码适用于OSX(Mavericks)和各种Ubuntu版本。