2017-05-15 5 views
4

があり、autowireできませんでした:は、私は春のアプリケーションでこのエラーが発生している(ただし、アプリケーションを実行し、[OK]を働いて)複数のBeanエラー

Could not autowire. There is more than one bean of 'OAuth2ClientContext' type. 
Beans: 
oauth2ClientContext   (OAuth2RestOperationsConfiguration.class) 
oauth2ClientContext   (OAuth2RestOperationsConfiguration.class) 
oauth2ClientContext   (OAuth2RestOperationsConfiguration.class) 

@SpringBootApplication 
@RestController 
@EnableOAuth2Client 
@EnableAuthorizationServer 
@Order(6) 
public class SocialApplication extends WebSecurityConfigurerAdapter { 

    @Autowired 
    OAuth2ClientContext oauth2ClientContext; 
} 

私は実際にそれがから来て、どのように場所を理解することはできません修理する。私はこの春のもので新しいです、あなたはそれを修正する方法を指摘することができますか、私は何を探すべきですか?私は豆を作成/注釈していません。

マイポンポンファイル

<parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.7.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.springframework.security</groupId> 
      <artifactId>spring-security-jwt</artifactId> 
      <version>1.0.4.RELEASE</version> 
     </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> 
+1

は、一意の名前で試してみましたが? – Stultuske

+0

私はあなたが話していることを理解しているshureではない、それは@Qualifierですか? – Evgenii

+0

私はあなたの依存関係だと思う。プロジェクトの依存関係は何ですか? – Arash

答えて

4

あなたは、おそらくあなたはのいずれかの方法で@Qualifier(name='OAuth1')を追加することができますか、のいずれかを設定することができ、それを修正するためにOAuth2ClientContext

の同じ名前を持つ1つの豆、より多くを持っていますそれらは@Primaryとなります。

例:

@Autowired 
@Qualifier(name = 'service1') 
private OAuth2ClientContext oauth; 

または作成し

Serviceあなたがこれを行うことができます:

@Service 
@Primary 
public class OAuth2ClientContext{ 

... 
... 
.. 
} 
+0

問題は - 私はこの豆を自分で作成しません。私が正しく理解すれば、春はそれを私のためにしています。なぜ私は@Primaryアノテーションを置くためにサービス/ Beans/Componentsを持っていないのですか?私はサービス/ Bean/etcの名前がわからないので、 "Qualify"するべきものがわかりません。 – Evgenii

+0

あなたがPOM.XMLにたくさんのSpring Securityライブラリを持っているのを見て、Spring-Bootが自動的にBeanを作成するので、おそらくSpringのBootが同じ名前を持つ2つのBeanを作成しているのでもの。 –

+0

あなたはこのセキュリティライブラリのすべてに問題がありました。ありがとうございました。 – Evgenii

関連する問題