所以,我在Zuul中添加了,为了让代理正常工作,我需要添加'spring-cloud-security‘,我就是这么做的:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-security</artifactId>
<version>1.1.0.M2</version>
</dependency>问题是,一旦我这样做了,我就会得到这个异常
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loadBalancedOauth2RestTemplate' defined in class path resource [org/springframework/cloud/security/oauth2/client/ OAuth2LoadBalancerClientAutoConfiguration$LoadBalancedOauth2RestTemplateConfig.class]: Unsatisfied dependency expressed through constructor argument with index 2 of typ[org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails]: : No qualifying bean of type [org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]如果我创建了一个bean,我会得到这个异常(我在props/yml之外指定资源服务器信息):
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.security.oauth2.client.OAuth2RestTemplate] is defined: expected single matching bean but found 2: userInfoRestTemplate,loadBalancedOauth2RestTemplate
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]我已经看过前一篇文章了:
https://github.com/spring-cloud/spring-cloud-security/issues/73
我正在使用Spring Boot 1.3.3.RELEASE。我已经尝试(从上面的帖子)添加到dep管理:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.M3</version>
<type>pom</type>
<scope>import</scope>
</dependency>但无济于事。
我认为这是一个“版本”的问题;使用的最新的库和版本是什么?我已经看过了AngularJS/Security教程中的'oauth2-vanilla-ui‘示例。是不是因为我没有在资源文件中使用道具?
发布于 2016-03-14 22:06:07
好的,所以我设法弄明白了。所以我把'spring-cloud-security‘的版本升级到了'1.1.0.M4’,因为我注意到一些autoconf已经改变了。此外,我将'OAuth2ProtectedResourceDetails‘保留为bean,并添加了一个'OAuth2RestTemplate’bean,但最重要的是,将其标记为主要的:
@Primary
@Bean(name = "platformClientRestTemplate")
public OAuth2RestTemplate clientRestTemplate() {
return new OAuth2RestTemplate(platformOAuth2ProtectedResourceDetails(), oauth2ClientContext);
} 这意味着多个RestTemplates的问题消失了(并确保使用我想要的rest模板)。
这意味着我正在使用(对于任何有版本问题的人):
Boot 1.3.3释放spring-cloud-security 1.1.0.M4 spring-cloud-starter-zuul 1.1.0.M3
https://stackoverflow.com/questions/35987344
复制相似问题