我正在使用Spring Integration项目开发SpringBoot。在升级我的应用程序时,我遇到了以下错误(仅限关键云而非本地) -
在上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称' cloudDataBaseConfiguration':通过字段' cloud'表达的不满意依赖项时出错:创建名称为' cloudMultiHttpSecurityConfig'的错误:通过字段表达的不满意的依赖关系ldapProvider':创建名称为' ldapProvider'在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义:通过方法< ldapProvider'表达的不满意的依赖关系参数0:创建名称为' iamClient'的bean时出错在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义:通过方法' iamClient'表达的不满意依赖性参数0:创建名称为' cloud'时出错:正在创建请求的bean:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为' cloud':请求bean当前正在创建时出错:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为' iamClient'的bean时出错在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义:通过方法' iamClient'表达的不满意依赖性参数0:创建名称为' cloud'时出错:正在创建请求的bean:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为' cloud':请求bean当前正在创建时出错:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为' ldapProvider'的bean时出错在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义:通过方法< ldapProvider'表达的不满意的依赖关系参数0:创建名称为' iamClient'的bean时出错在类路径资源[com / fidintl / bs / addcash / config / CloudMultiHttpSecurityConfig.class]中定义:通过方法' iamClient'表达的不满意依赖性参数0:创建名称为' cloud'时出错:正在创建请求的bean:是否存在无法解析的循环引用?嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为' cloud':请求bean当前正在创建时出错:是否存在无法解析的循环引用?
我的配置类 -
@Configuration
@EnableWebSecurity
@Order(Ordered.HIGHEST_PRECEDENCE)
@Profile("cloud")
public class CloudMultiHttpSecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(CloudMultiHttpSecurityConfig.class);
@Autowired
private AuthenticationProvider ldapProvider;
@Autowired
private Environment env;
@Bean
public Cloud cloud() {
return new CloudFactory().getCloud();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(ldapProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated();
http.httpBasic();
http.csrf().disable();
}
@Bean
public AuthenticationProvider ldapProvider(IAMClient iamClient, Cloud cloud) {
IamLdapServiceInfo iamServiceInfo = (IamLdapServiceInfo) cloud.getServiceInfo("ldap-provider-info");
return new AdvLdapAuthProvider(iamServiceInfo, new IAMAuthorityProvider(iamClient));
}
@Bean
public IAMClient iamClient(Cloud cloud) throws Spml2Exception {
WebServiceInfo serviceInfo = (WebServiceInfo) cloud.getServiceInfo("iam-client-info");
IAMClient iamClient = new IAMClient(new Spml2Client(serviceInfo.getUri()), serviceInfo.getAppName(), serviceInfo.getUserName(), serviceInfo.getPassword());
return iamClient;
}
@Bean
public SonUrlService sonataServiceInfo(Cloud cloud) {
LOGGER.info("Inside sonataServiceInfo Bean, type of serviceInfoBean :" + cloud.getServiceInfo("SonUrlService" + env.getProperty("ups_envn")).getClass());
return (SonUrlService) cloud.getServiceInfo("SonUrlService" + env.getProperty("ups_envn"));
}
@Bean
public QueueConnectionFactoryServiceInfo mqServiceInfo(Cloud cloud) {
LOGGER.info("Inside QueueConnectionFactoryServiceInfo Bean, type of mqServiceInfo :" + cloud.getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn")).getClass());
return (QueueConnectionFactoryServiceInfo) cloud.getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn"));
}
@Bean
public QueueNamesServiceInfo queueNamesServiceInfo(Cloud cloud) {
return (QueueNamesServiceInfo) cloud.getServiceInfo("QueueNames_" + env.getProperty("ups_envn"));
}
}
pom.xml -
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath />
</parent>
只有当我把它推向关键云时,这个问题才会出现在本地。
答案 0 :(得分:2)
你能尝试这样做吗?可以通过cloud()方法直接访问云依赖。
@Configuration
@EnableWebSecurity
@Order(Ordered.HIGHEST_PRECEDENCE)
@Profile("cloud")
public class CloudMultiHttpSecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(CloudMultiHttpSecurityConfig.class);
@Autowired
private AuthenticationProvider ldapProvider;
@Autowired
private Environment env;
@Bean
public Cloud cloud() {
return new CloudFactory().getCloud();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(ldapProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated();
http.httpBasic();
http.csrf().disable();
}
@Bean
public AuthenticationProvider ldapProvider(IAMClient iamClient) {
IamLdapServiceInfo iamServiceInfo = (IamLdapServiceInfo) cloud().getServiceInfo("ldap-provider-info");
return new AdvLdapAuthProvider(iamServiceInfo, new IAMAuthorityProvider(iamClient));
}
@Bean
public IAMClient iamClient() throws Spml2Exception {
WebServiceInfo serviceInfo = (WebServiceInfo) cloud().getServiceInfo("iam-client-info");
IAMClient iamClient = new IAMClient(new Spml2Client(serviceInfo.getUri()), serviceInfo.getAppName(), serviceInfo.getUserName(), serviceInfo.getPassword());
return iamClient;
}
@Bean
public SonUrlService sonataServiceInfo() {
LOGGER.info("Inside sonataServiceInfo Bean, type of serviceInfoBean :" + cloud().getServiceInfo("SonUrlService" + env.getProperty("ups_envn")).getClass());
return (SonUrlService) cloud().getServiceInfo("SonUrlService" + env.getProperty("ups_envn"));
}
@Bean
public QueueConnectionFactoryServiceInfo mqServiceInfo() {
LOGGER.info("Inside QueueConnectionFactoryServiceInfo Bean, type of mqServiceInfo :" + cloud().getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn")).getClass());
return (QueueConnectionFactoryServiceInfo) cloud().getServiceInfo("QueueConnectionFactory_" + env.getProperty("ups_envn"));
}
@Bean
public QueueNamesServiceInfo queueNamesServiceInfo() {
return (QueueNamesServiceInfo) cloud().getServiceInfo("QueueNames_" + env.getProperty("ups_envn"));
}
}