apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.23k stars 8.76k forks source link

Error creating bean with name 'scopedTarget.accessTokenRequest' #1168

Closed cashZhang27 closed 5 years ago

cashZhang27 commented 5 years ago

Ⅰ. Issue Description

When I use the following dependencies and @EnableOAuth2Client

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-oauth2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.security.oauth</groupId>
      <artifactId>spring-security-oauth2</artifactId>
      <version>2.3.3.RELEASE</version>
    </dependency>

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

4270FAF3-BD4A-4fe0-BFF1-DE601103B52F

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. xxx
  2. xxx
  3. xxx

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

fescar-robot commented 5 years ago

Hi @cashZhang27, we detect non-English characters in the issue. This comment is an auto translation from @fescar-robot to help other users to understand this issue. We encourage you to describe your issue in English which is more friendly to other users.

Error creating bean with name 'scopedTarget.accessTokenRequest'

Ⅰ. Issue Description

When I use the following dependencies and @EnableOAuth2Client

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.security.oauth</groupId>
  <artifactId>spring-security-oauth2</artifactId>
  <version>2.3.3.RELEASE</version>
</dependency>

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

![4270FAF3-BD4A-4fe0-BFF1-DE601103B52F](https://user-images.githubusercontent.com/30404342/58884488-1cdec280-8713-11e9-88ae-f1a9c01c355d.png)

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

  1. xxx
  2. xxx
  3. xxx

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

leizhiyuan commented 5 years ago

how to reproduce the issue?

cashZhang27 commented 5 years ago

how to reproduce the issue?

@leizhiyuan For example, Use the following dependencies and @EnableOAuth2Client to start an error in the seata-samples order application,The picture above the error log can be seen,Sorry, my English is very bad,,,

 <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-oauth2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.security.oauth</groupId>
      <artifactId>spring-security-oauth2</artifactId>
      <version>2.3.3.RELEASE</version>
    </dependency>
xingfudeshi commented 5 years ago

how to reproduce the issue?

@leizhiyuan For example, Use the following dependencies and @EnableOAuth2Client to start an error in the seata-samples order application,The picture above the error log can be seen,Sorry, my English is very bad,,,

 <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-oauth2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.security.oauth</groupId>
      <artifactId>spring-security-oauth2</artifactId>
      <version>2.3.3.RELEASE</version>
    </dependency>

It seems it's not the problem of seata,but like dependency conflicts.

cashZhang27 commented 5 years ago

how to reproduce the issue?

@leizhiyuan For example, Use the following dependencies and @EnableOAuth2Client to start an error in the seata-samples order application,The picture above the error log can be seen,Sorry, my English is very bad,,,

 <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-oauth2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.security.oauth</groupId>
      <artifactId>spring-security-oauth2</artifactId>
      <version>2.3.3.RELEASE</version>
    </dependency>

It seems it's not the problem of seata,but like dependency conflicts.

@xingfudeshi I am very appreciate it that you response it so quickly. But I try to exclusion spring-security-oauth2-autoconfigure or spring-security-oauth2 can't solve this problem. it is normal when I don't apply seata.can you tell me which dependency I need to exclude? thank you for your response again image

xuande commented 5 years ago

I have the same question. Did you solved?

cashZhang27 commented 5 years ago

@xuande No, I have no idea at all... I am waiting for seata to solve

xingfudeshi commented 5 years ago

@xuande No, I have no idea at all... I am waiting for seata to solve add a Configuration class like this in your application.


import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration;

/**

}

cashZhang27 commented 5 years ago

@xingfudeshi I tested it in a seata-samples and it didn't seem to change...Was I misconfigured? 微信截图_20190629202330

xingfudeshi commented 5 years ago

Can you pull the latest code of seata,and install the 0.7.0-snapshot at local,then try it again?My testing was passed with it.We've optimized the priority of GlobalTransactionScanner in the 0.7.0,it will solve your problem.

zhuyoufeng commented 5 years ago

SpringProxyUtils wants to get the Class of the proxy object, but if the scope of the class is web scope, spring cannot get the request, just call getTargetClass will be OK, hope it can help you.

modify the class io.seata.spring.util.SpringProxyUtils as following: `

public static Class<?> findTargetClass(Object proxy) throws Exception {

    if (AopUtils.isAopProxy(proxy)) {
        AdvisedSupport advised = getAdvisedSupport(proxy);
        if (AopUtils.isJdkDynamicProxy(proxy)) {
            TargetSource targetSource = advised.getTargetSource();
            // remove 
            // return targetSource instanceof EmptyTargetSource ? getFirstInterfaceByAdvised(advised)
                : targetSource.getTarget().getClass();
           // add
            return targetSource instanceof EmptyTargetSource ? getFirstInterfaceByAdvised(advised)
                : targetSource.getTargetClass();
        }
        Object target = advised.getTargetSource().getTarget();
        return findTargetClass(target);
    } else {
        return proxy == null ? null :proxy.getClass();
    }

} `