Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Spring拒绝带有代理模式接口的请求范围bean的@Qualifier?_Spring_Dependency Injection - Fatal编程技术网

为什么Spring拒绝带有代理模式接口的请求范围bean的@Qualifier?

为什么Spring拒绝带有代理模式接口的请求范围bean的@Qualifier?,spring,dependency-injection,Spring,Dependency Injection,我的界面: public interface SomeInterface {} 由请求范围的bean实现: @Component @Qualifier("q") @Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.INTERFACES) public class Implementation implements SomeInterface { } 考虑到类似这样的建议,

我的界面:

public interface SomeInterface {}
由请求范围的bean实现:

@Component
@Qualifier("q")
@Scope(value = WebApplicationContext.SCOPE_REQUEST,
       proxyMode = ScopedProxyMode.INTERFACES)
public class Implementation implements SomeInterface { }
考虑到类似这样的建议,代理模式
接口
应该适合这种非常干净的设置

由于我想以几种不同的
SomeInterface
实现作为结束,我加入了一个额外的
@Qualifier(“q”)

然而,Spring完全拒绝了限定符,表现得好像周围没有合适的
@组件

例如,以下测试失败,典型的
unsatisfiedPendencyException
表示Spring“至少需要1个符合autowire候选资格的bean”,但在
@org.springframework.beans.factory.annotation.Qualifier(value=q)
中未找到

相反,选择标准bean名称可以使事情正常工作:

@Autowired
@Qualifier("implementation")
private SomeInterface cut; // <-- works
@Component("q")
@Scope(value = WebApplicationContext.SCOPE_REQUEST, 
       proxyMode = ScopedProxyMode.INTERFACES)
public class Implementation implements SomeInterface { }
@Component("q")
@Scope(value = WebApplicationContext.SCOPE_REQUEST, 
       proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Implementation implements SomeInterface { }
另外,将代理模式更改为
TARGET\u CLASS
可以使该功能正常工作:

@Autowired
@Qualifier("implementation")
private SomeInterface cut; // <-- works
@Component("q")
@Scope(value = WebApplicationContext.SCOPE_REQUEST, 
       proxyMode = ScopedProxyMode.INTERFACES)
public class Implementation implements SomeInterface { }
@Component("q")
@Scope(value = WebApplicationContext.SCOPE_REQUEST, 
       proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Implementation implements SomeInterface { }

代理模式
接口有什么特别之处,以至于它不能与
@Qualifier
一起工作?

如果删除实现类上的Qualifier注释并使用
@Component(“q”)
设置组件名称,则测试通过。但是我不知道为什么它不能与限定符一起工作,如果您删除范围注释,它为什么会工作。如果您删除实现类上的限定符注释并使用
@Component(“q”)
设置组件名称,则测试通过。但是我不知道为什么它不能与限定符一起使用,以及如果删除范围注释为什么会这样。