簡體   English   中英

考慮在您的配置中定義一個“com.example.amazonsync.Service.IAmazonUtilService”類型的 bean

[英]Consider defining a bean of type 'com.example.amazonsync.Service.IAmazonUtilService' in your configuration

我的服務類中出現空指針異常。 我已自動裝配名為 IAmazonUtilService 的 myservice 類。 但它正面臨空指針異常。

我還編寫了 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.

導入AmazonDataService.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

改變由工具延伸!!

從:

public class AmazonUtilService extends ImportAmazonDataService {}

到:

public class AmazonUtilService implements ImportAmazonDataService {}

你的ImportAmazonDataService類應該被注釋為@Service以便 spring 知道注入@Autowired IAmazonUtilService

也重構

@Autowired
private IAmazonUtilService IAmazonUtilService;

@Autowired
private IAmazonUtilService iAmazonUtilService;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM