考虑在您的配置中定义'com.example.amazonsync.Service.IAmazonUtilService'类型的Bean

问题描述 投票:0回答:2

我在服务类中收到空指针异常。我已经自动连接了名为IAmazonUtilService的myservice类。但是它面临着null的veervexception。

另外,我已经编写了PropertiesUtil以便从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.

ImportAmazonDataService.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

java spring spring-boot spring-data-jpa quartz-scheduler
2个回答
0
投票

变更由工具扩展!

来自:

public class AmazonUtilService extends ImportAmazonDataService {}

至:

public class AmazonUtilService implements ImportAmazonDataService {}

0
投票

您的ImportAmazonDataService类应注释为@Service,以便spring知道注入@Autowired IAmazonUtilService

也重构

@Autowired
private IAmazonUtilService IAmazonUtilService;

@Autowired
private IAmazonUtilService iAmazonUtilService;
© www.soinside.com 2019 - 2024. All rights reserved.