当前位置: 首页 > 知识库问答 >
问题:

考虑定义“com”类型的bean。实例亚马逊同步。服务配置中的IAmazonUtilService

陈扬
2023-03-14

我的服务类中出现空指针异常。我有一个名为IAmazonUtilService的自动连线myservice类。但它面临着null pointervexception。

另外,我写了属性Util从application.properties读取数据,这也是不工作的。请帮帮我。

2020-03-27 18:39:20.172  INFO 17536 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
java.lang.NullPointerException
    at com.example.amazonsync.AmazonSync.ImportAmazonDataService.getOrdersFromAmazonStore(ImportAmazonDataService.java:36)
ImportAmazonDataService.java:36
    at com.example.amazonsync.SyncData.OrderSync.execute(OrderSync.java:17)
OrderSync.java:17
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
JobRunShell.java:202
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
SimpleThreadPool.java:573
2020-03-27 18:39:20.254  INFO 17536 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2020-03-27 18:39:20.263  INFO 17536 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-03-27 18:39:20.330  INFO 17536 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-27 18:39:20.841 ERROR 17536 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field IAmazonUtilService in com.example.amazonsync.AmazonSync.ImportAmazonDataService required a bean of type 'com.example.amazonsync.Service.IAmazonUtilService' that could not be found.

重要的Amazon数据ervice.java

public class ImportAmazonDataService {

    @Autowired
    private IAmazonUtilService IAmazonUtilService;

    public ArrayList<String> getChannelLoc() {
        ArrayList<String> channelLoc = new ArrayList<String>();
        channelLoc.add("US");
        channelLoc.add("CA");
        channelLoc.add("MX");
        return channelLoc;
    }

    public void getProductsFromAmazonStore(JobExecutionContext context) throws SQLException, ClassNotFoundException {
        try {
            final Long taskID = (Long) context.getJobDetail().getJobDataMap().get("taskId");
            IAmazonUtilService.getChannelConfig("US");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getOrdersFromAmazonStore(JobExecutionContext context) throws SQLException, ClassNotFoundException {

        final long taskID = (long) context.getJobDetail().getJobDataMap().get("taskId");
        IAmazonUtilService.getChannelConfig("CA");
    }
}

Git链接:https://github.com/Ezhilarasu1330/SpringBootQuartzSchedular.git

共有2个答案

岳彬炳
2023-03-14

您的importamazonnataservice类应注释为Service,以便spring知道如何注入自动连接的IAmazonUtilService

同时重构

@Autowired
private IAmazonUtilService IAmazonUtilService;

@Autowired
private IAmazonUtilService iAmazonUtilService;
巫新知
2023-03-14

更改按工具扩展!!

发件人:

public class AmazonUtilService extends ImportAmazonDataService {}

收件人:

public class AmazonUtilService implements ImportAmazonDataService {}
 类似资料: