2017-07-19 3 views
0

私はOAuth2でSpring Bootを使用していますが、トークンを取り消そうとしています。しかし、私はそれらのクラスを自動配線しようとすると、彼らはすでにResourceServerTokenServicesConfiguration.classにいると私に伝えます。私はどこにいても私のコード(これは非常に単純です)にはありません。AuthorizationServerTokenServicesまたはConsumerTokenServicesを自動配線できないのはなぜですか? "[this]タイプの複数のBeanがあります"

注:私は(コンポーネント、コントローラ、SpringBootApplication、など)でこれを試してみてください内の任意のクラスを、このエラーが発生します。

私にこれらを注入できるようにするにはどうすればよいですか?

IDE(IntelliJの)エラー:

Could not autowire. There is more than one bean of '' type.

Beans: jwkTokenServices (ResourceServerTokenServicesConfiguration.class) jwkTokenServices (ResourceServerTokenServicesConfiguration.class)

春のランタイムエラー:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] 
    at com.simple.SimpleApplication.main(SimpleApplication.java:40) [classes/:na] 

Field authorizationServerTokenServices in com.simple.SimpleApplication required a bean of type 'org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices' that could not be found. 
    - Bean method 'jwkTokenServices' not loaded because OAuth JWK Condition did not find key jwk set URI not provided 
    - Bean method 'jwtTokenServices' not loaded because OAuth JWT Condition did not find provided public key 

はのpom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.simple</groupId> 
    <artifactId>simple</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>simple</name> 
    <description>SSO project for Spring Boot</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
     <relativePath /> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-security</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security.oauth</groupId> 
      <artifactId>spring-security-oauth2</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.webjars</groupId> 
      <artifactId>angularjs</artifactId> 
      <version>1.4.3</version> 
     </dependency> 
     <dependency> 
      <groupId>org.webjars</groupId> 
      <artifactId>jquery</artifactId> 
      <version>2.1.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.webjars</groupId> 
      <artifactId>bootstrap</artifactId> 
      <version>3.2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.webjars</groupId> 
      <artifactId>webjars-locator</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

私はエラーを取得するクラス:

package com.simple; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint; 
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; 
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 

import javax.annotation.Resource; 
import javax.servlet.http.HttpServletRequest; 

@FrameworkEndpoint 
public class RevokeTokenEndpoint { 

    @Autowired 
    private AuthorizationServerTokenServices authorizationServerTokenServices; 

    @Autowired 
    private ConsumerTokenServices consumerTokenServices; 


} 

application.yml

security: 
oauth2: 
    client: 
    clientId: myclientid 
    clientSecret: myclientsecret 
    accessTokenUri: https://graph.facebook.com/oauth/access_token 
    userAuthorizationUri: https://www.facebook.com/dialog/oauth 
    tokenName: oauth_token 
    authenticationScheme: query 
    clientAuthenticationScheme: form 
    sso: 
    login-path: /login 
    resource: 
    userInfoUri: https://graph.facebook.com/me 

logging: 
level: 
    org.springframework.security: DEBUG 
    org.springframework.web: DEBUG 

答えて

0

は、おそらくこれは、私はあなたが右

+0

これらのクラスを使用してトークンを取り消すにはどうすればよいですか?私は既にそれらを持っているクラスを自動配線しようとしましたが、それを公開していません。 –

+0

質問に実際のエラーを追加してください。 –

+0

OK、エラーを追加しました。ありがとう! –

0

に疑問を持った場合、このようなタイプのいくつかの豆があるように思え、春から提供されるデフォルト設定です。したがって、Autowireの作業を行うためにBeanの名前を指定する必要があります。

@Autowire 
private AuthorizationServerTokenServices defaultAuthorizationServerTokenServices; 

私のために働きます。

関連する問題