春天的PayPal API方面的问题

问题描述:

而在春季启动应用IM整合贝宝让这个问题春天的PayPal API方面的问题

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 

*************************** 
APPLICATION FAILED TO START 
*************************** 

Description: 

Field apiContext in com.bookstore.service.impl.PaypalService required a bean of type 'com.paypal.base.rest.APIContext' that could not be found. 


Action: 

Consider defining a bean of type 'com.paypal.base.rest.APIContext' in your configuration. 

我主要的样子

@SpringBootApplication 
@EnableAutoConfiguration 
@Configuration 
@ComponentScan 
public class BookstoreAngularApplication implements CommandLineRunner { 

错误点的地方,我已经使用的API方面的服务paypal

import com.paypal.api.payments.Transaction; 
import com.paypal.base.rest.APIContext; 
import com.paypal.base.rest.PayPalRESTException; 
    @Autowired 
     private APIContext apiContext; 

     public Payment createPayment(
       Double total, 
       String currency, 
       PaypalPaymentMethod method, 
       PaypalPaymentIntent intent, 
       String description, 
       String cancelUrl, 
       String successUrl) throws PayPalRESTException{ 
      Amount amount = new Amount(); 
      amount.setCurrency(currency); 
      amount.setTotal(total.toString()); 

      Transaction transaction = new Transaction(); 
      transaction.setDescription(description); 
      transaction.setAmount(amount); 

      List<Transaction> transactions = new ArrayList<>(); 
      transactions.add(transaction); 

      Payer payer = new Payer(); 
      payer.setPaymentMethod(method.toString()); 

      Payment payment = new Payment(); 
      payment.setIntent(intent.toString()); 
      payment.setPayer(payer); 
      payment.setTransactions(transactions); 
      RedirectUrls redirectUrls = new RedirectUrls(); 
      redirectUrls.setCancelUrl(cancelUrl); 
      redirectUrls.setReturnUrl(successUrl); 
      payment.setRedirectUrls(redirectUrls); 

      return payment.create(apiContext); 
     } 

     public Payment executePayment(String paymentId, String payerId) throws PayPalRESTException{ 
      Payment payment = new Payment(); 
      payment.setId(paymentId); 
      PaymentExecution paymentExecute = new PaymentExecution(); 
      paymentExecute.setPayerId(payerId); 
      return payment.execute(apiContext, paymentExecute); 
     } 

我有项目运行贝宝sdk工作正常,但是当我将它添加到我的应用程序im生病荷兰国际集团的PayPal API方面的这个错误

enter image description here

enter image description here

我从来没有使用过com.paypal.base.rest.APIContext之前,但您的错误信息表明,你需要APIContext类型的豆,因此它可以被装配。

考虑在你的配置中定义一个类型为'com.paypal.base.rest.APIContext'的类型为 的Bean。

尝试将bean添加到您的配置类(或xml文件,如果您仍然使用基于.xml的配置)。阅读com.paypal.base.rest.APIContextdocumentation我猜想,你需要的东西,如:

@Configuration 
public class AppConfiguration { 

    @Bean 
    public APIContext apiContext() { 
     APIContext apiContext = new APIContext("yourClientID", "yourClientSecret", "yourMode"); 
     return apiContext; 
    } 

试试这个,看看是否可行。请记住,AppConfiguration必须放置在BookstoreAngularApplication的子包中,以便可以加载。这是一个example

后来,从配置文件中读取"yourClientID", "yourClientSecret", "yourMode"而不是硬编码它。

+0

我已经配置它们,并在Appproperties中添加了键并将它们命名为检查我的更新楼上的请求 – tero17

+0

但现在是什么错误消息?它仍然是一样的吗? – Rafa

+0

他们从开始@Rafa – tero17

这是因为我把put的配置文件的包的名称必须像base-packages。*我已经在开始时提出了一个快速名称我现在修复它并使其成为其他名称扫描的包名并正常工作