jenkins釋出服務失敗檢視catalina.out啟動日誌和xxl-job jobhandler naming conflicts

oktokeep發表於2024-05-22

jenkins釋出服務失敗檢視catalina.out啟動日誌和xxl-job jobhandler naming conflicts

1.檢視tomcat/logs/catalina.out 日誌,發現和定位問題:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2024-04-26 13:55:36.872 [localhost-startStop-1][orderCoreApi,,,] ERROR o.s.boot.SpringApplication#reportFailure [line:771] - Application startup failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxlJobExecutor' defined in class path resource [com/myProject/xxljob/XxlJobConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: xxl-job jobhandler naming conflicts.

Caused by: java.lang.RuntimeException: xxl-job jobhandler naming conflicts.

2.如下程式碼,如果專案中存在“mySendSmsJobTask”重複,則會在專案啟動的時候,報以上錯誤。

@Component
@JobHandler("mySendSmsJobTask")
public class MySendSmsJobTask extends IJobHandler {
    private Logger logger = LoggerFactory.getLogger(MySendSmsJobTask.class);

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        Transaction t = Cat.getProducer().newTransaction(CatConstants.XXL_JOB_CALL, "定時查詢 定時任務傳送簡訊 定時任務");
        try {
            Cat.logEvent(CatConstants.XXL_JOB_METHOD,"MySendSmsJobTask.execute");
            Cat.logEvent(CatConstants.XXL_JOB_PARAM,null);
            logger.info("開始執行 定時任務傳送簡訊  定時器");
            XxlJobLogger.log("開始執行 定時任務傳送簡訊 定時器");

            //定時任務業務邏輯處理
            
            logger.info("結束執行 定時任務傳送簡訊 ");
            XxlJobLogger.log("結束執行 定時任務傳送簡訊 ");
            t.setStatus(Transaction.SUCCESS);
            return SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log("執行 定時任務傳送簡訊 異常:" + e);
            logger.error("執行 定時任務傳送簡訊 異常",e);
            Cat.logError("執行 定時任務傳送簡訊 異常",e);
            t.setStatus(e);
            return new ReturnT(FAIL.getCode(),e.toString());
        } finally {
            if (t != null) {
                t.complete();
            }
        }
    }
}

相關文章