执行器的执行流程

时间:2019-06-24 07:11:50

标签: spring-boot-actuator

我已经在Spring Boot应用程序中实现了Actuator,并且当我从诸如Eclipse之类的想法运行主类时执行了这些执行器代码,但是当我从终端运行.jar时,该代码不在运行时执行。在弹簧启动执行器中运行主类或运行罐子时有什么区别吗?

我已经尝试通过在运行主类时而不是在运行jar文件时放置一些sysout并打印出来。

@Component
public class MicroServiceInfoConfiguror implements HealthIndicator, InfoContributor {

    private static final Logger logger = LoggerFactory.getLogger(MicroserviceHealthIndicator.class);

    @PersistenceContext
    private EntityManager em;

    @Override
    public void contribute(Info.Builder builder) {
        int a = 10/0;
        System.out.println("*****************************Info***************************************************");
    }

    @Override
    public Health health() {
        int a = 10/0;
        System.out.println("Here in health indicator..........................***********************************************");
        int errorCode = check(); // perform some specific health check
        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }

    @Transactional(readOnly = true)
    private int check() {
        Integer count = null;
        try {
            Query query = em.createNativeQuery("select count(1) FROM system");
            List results = query.getResultList();
            for (Object next : results) {
                count = ((BigInteger) next).intValue();
            }
            logger.info("Health Check:" + count);
            System.out.println("Health Check:" + count);
        } catch (Exception e) {
            logger.error("Exception occurred in check()", e);
        }
        return (count != null && count.intValue() > 0) ? 0 : -1;
    }

}

在两种情况下都应打印所有sysout

0 个答案:

没有答案