2017-09-04 70 views
1

而在春季啓動應用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

回答

0

我從來沒有使用過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

0

這是因爲我把put的配置文件的包的名稱必須像base-packages。*我已經在開始時提出了一個快速名稱我現在修復它並使其成爲其他名稱掃描的包名並正常工作