Could not autowire, there is more than one bean error

Evgenii :

I have this error in spring application(But application Running and working ok):

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;
}

I really can't understand where it coming from and how to fix it. I'm new with this spring stuff, can you point out how to fix it or what should I look for. I'm not creating/annotating beans.

My pom file

    <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>
José Mendes :

You probably have more then one bean with the same name of OAuth2ClientContext

To fix it you can add a @Qualifier(name='OAuth1') at one of the methods or you can set one of them as @Primary.

Example:

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

OR

Where you created your Service you can do this:

@Service
@Primary
public class OAuth2ClientContext{

...
...
..
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=469590&siteId=1