java - 创建 bean 时出错;通过字段表示的不满足的依赖关系
问题描述
我有一个用于某些功能的中央库,现在我无法集成该库。该库是用 Spring Boot 编写的,包含一个类:com.common.Security。它是这样定义的:
package com.common;
....
@Service
@EnableConfigurationProperties(SecurityProperties.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Security {
....
}
我尝试在另一个类中使用它:
package org.special;
import com.common.Security;
@Configuration
public class WebServiceConfig {
@Autowired
private Security security;
....
}
但我得到一些错误:
Error creating bean with name 'myController': Unsatisfied dependency expressed through field 'WebServiceclient';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'webserviceClient':
Unsatisfied dependency expressed through field 'template'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'webServiceTemplate' defined in class path resource [org/special/WebServiceConfig.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.ws.client.core.WebServiceTemplate]: Factory method 'webServiceTemplate' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException:
nested exception is org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'scopedTarget.Security': Scope 'request' is not active for the current thread;
consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found:
我能做些什么来解决这个问题?
解决方案
删除范围非常有帮助。我之前尝试过这个,但在那之后我的一些测试失败了。我没有看到,这是因为 application.yaml 中缺少测试设置。当要求范围时,它们不是必需的。
推荐阅读
- json - 在 CloudFormation Powershell 脚本中调用参数
- vb.net - VB.NET EntryPointNotFoundException
- c++ - 如果在大小范围内,C++ 从标准输入读取
- excel - 范围宏不起作用
- ubuntu - 无法在 127.0.0.1:6379 连接到 Redis:网络无法访问
- python-3.x - 我可以直接通过 Tweepy 访问用户的描述(简历)吗?
- excel - {MS Access] 如何联合两个表而不重复数据?
- spring - Heroku:自定义域,ACM 状态:DNS 重定向不是转发路径,怎么办?
- javascript - 无法使用无渲染组件实现 vuelidate - vue js
- sql - Sql - 获取特定ID的表中值的总和