使用jenkins启动SpringBoot报错

本文主要描述了在使用Jenkins部署SpringBoot项目时遇到的启动错误问题。错误出现在使用AsyncTask和多线程调度时,由于类之间的循环注入导致。通过分析日志,发现问题在于业务层和服务层之间的循环依赖。解决方法是调整asyncTask的引用,避免在serviceImpl中引用其他service接口,直接使用dao层进行操作,从而消除循环注入,确保应用正常启动。
摘要由CSDN通过智能技术生成

jenkins启动SpringBoot偶尔会报错!

启动SpringBoot的项目的时候。

1、环境

  1. springboot
  2. jdk 1.8
  3. jenkins部署

2、代码

1.使用了AsyncTask

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import java.util.concurrent.Future;

@Component
public class AsyncTask {
   

    @Autowired
    private AsyncTaskService asyncTaskService;

    private final static String CALL_BACK = "success";

    @Async
    public Future<String> addUserGroupReadCount(Integer groupId,Integer count) throws Exception {
   
        asyncTaskService.addUserGroupReadCount(groupId,count);
        return new AsyncResult<String>(CALL_BACK);
    }
}

2.设置了AsyncTaskConfig

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.lang.reflect.Method;
import java.util.concurrent.Executor;

@EnableAsync
@Configuration
@ComponentScan("com.meyoung.cloudguide.task")
public class AsyncTaskConfig implements AsyncConfigurer {
   

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public Executor getAsyncExecutor() {
   
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(10);
        taskExecutor.setMaxPoolSize(500);
        taskExecutor.setQueueCapacity(25);
        taskExecutor.setAwaitTerminationSeconds(60);
        taskExecutor.setThreadNamePrefix("MeYoungAsync-Manage-");
        taskExecutor.initialize();
        return taskExecutor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
   
        return new SpringAsyncExceptionHandler();
    }

    class SpringAsyncExceptionHandler implements AsyncUncaughtExcept
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值