所以,我已经在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>
但无济于事。
我希望这是一个'版本'问题;什么是最新的libs&amp; amp;要使用的版本?我已经浏览过AngularJS / Security教程中的'oauth2-vanilla-ui'示例。是因为我没有在资源文件中使用道具吗?
答案 0 :(得分:0)
好的,所以我设法搞清楚了。所以我把'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的问题消失了(并确保我想要的其余模板被使用)。
这意味着我正在使用(对于有版本问题的任何人):
启动1.3.3.RELEASE spring-cloud-security 1.1.0.M4 spring-cloud-starter-zuul 1.1.0.M3