Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringPayPalAPI上下文问题_Java_Spring_Paypal - Fatal编程技术网

Java SpringPayPalAPI上下文问题

Java SpringPayPalAPI上下文问题,java,spring,paypal,Java,Spring,Paypal,在spring boot应用程序中集成paypal时,我发现了这个问题 Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. *************************** APPLICATION FAILED TO START *************************** De

在spring boot应用程序中集成paypal时,我发现了这个问题

    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 {
错误指向我使用paypal api上下文的服务

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);
        }
import com.paypal.api.payments.Transaction;
导入com.paypal.base.rest.APIContext;
导入com.paypal.base.rest.PayPalRESTException;
@自动连线
私有APIContext-APIContext;
公共支付(
双倍总数,
字符串货币,
支付方式,
支付意向,
字符串描述,
字符串取消URL,
字符串successUrl)引发PayPalRESTException{
金额=新金额();
金额。设置货币(币种);
amount.setTotal(total.toString());
事务=新事务();
事务.setDescription(描述);
交易。设置金额(金额);
列表事务=新建ArrayList();
交易。添加(交易);
付款人付款人=新付款人();
payer.setPaymentMethod(method.toString());
付款=新付款();
payment.setIntent(intent.toString());
付款。设置付款人(付款人);
支付。设置交易(交易);
RedirectUrls RedirectUrls=新的重定向URL();
重定向URL.setCancelUrl(取消URL);
重定向URL.setReturnUrl(成功URL);
支付。设置重定向URL(重定向URL);
返回付款。创建(apiContext);
}
public Payment executePayment(字符串paymentId,字符串PayRid)引发PayPalRESTException{
付款=新付款();
payment.setId(paymentId);
PaymentExecution paymentExecute=新的PaymentExecution();
paymentExecute.setPayerId(payerId);
返回payment.execute(apiContext,paymentExecute);
}
我有一个运行paypal sdk的项目运行良好,但当我将它添加到我的应用程序时,我对paypal api上下文的这个错误感到恶心


我以前从未使用过
com.paypal.base.rest.APIContext
,但您的错误消息表明您需要一个类型为
APIContext
的bean,以便可以自动连接

考虑在中定义“com.paypal.base.rest.APIContext”类型的bean 您的配置

尝试将bean添加到配置类(如果仍然使用基于.xml的配置,则添加到xml文件)。阅读
com.paypal.base.rest.APIContext
我猜您需要类似以下内容:

@Configuration
public class AppConfiguration {

    @Bean
    public APIContext apiContext() {
        APIContext apiContext = new APIContext("yourClientID", "yourClientSecret", "yourMode");
        return apiContext;
    }
试试这个,看看是否有效。请记住,
AppConfiguration
必须放在
BookstoreAngularApplication
的子包中,以便加载。这是一个例子


稍后,从配置文件中读取
“yourClientID”、“yourClientSecret”、“yourMode”
,而不是硬编码。

我以前从未使用过
com.paypal.base.rest.APIContext
,但您的错误消息表明,您需要一个
APIContext
类型的bean,以便可以自动连接

考虑在中定义“com.paypal.base.rest.APIContext”类型的bean 您的配置

尝试将bean添加到配置类(如果仍然使用基于.xml的配置,则添加到xml文件)。阅读
com.paypal.base.rest.APIContext
我猜您需要类似以下内容:

@Configuration
public class AppConfiguration {

    @Bean
    public APIContext apiContext() {
        APIContext apiContext = new APIContext("yourClientID", "yourClientSecret", "yourMode");
        return apiContext;
    }
试试这个,看看是否有效。请记住,
AppConfiguration
必须放在
BookstoreAngularApplication
的子包中,以便加载。这是一个例子


稍后,阅读“yourClientID”、“yourClientSecret”、“yourMode”来自配置文件,而不是硬编码。

这是因为我放入配置文件的包的名称必须与基本包类似。*我在开始时放入了一个快速名称,我现在将其修复,并使其与扫描的其他包的名称一样,工作正常

这是因为我放入的包的名称配置文件必须类似于基本软件包。*我在开始时使用了一个快速名称我现在修复它,并使其成为与其他软件包一样的软件包名称它被扫描并且工作正常

我已经这样配置它们,并在Appproperties中添加了密钥并调用它们检查我的更新,但是现在出现了什么错误消息?还是一样吗?他们从一开始就在@RafaI会猜spring boot没有读取
PaypalConfig
。确保spring引导加载
PaypalConfig
,添加
System.out.println(“TetingConfig”)
,并检查是否正在加载。另外,试着按照这些步骤去做。如果对您有效,请标记为“已回答”。Cheers我已经这样配置了它们,在Appproperties中添加了键,并调用它们检查我的更新,但是现在的错误消息是什么?还是一样吗?他们从一开始就在@RafaI会猜spring boot没有读取
PaypalConfig
。确保spring引导加载
PaypalConfig
,添加
System.out.println(“TetingConfig”)
,并检查是否正在加载。另外,试着按照这些步骤去做。如果对您有效,请标记为“已回答”。干杯