在一个可以正常运行的micronaut项目中,我在启动时看到了以下日志记录:
> Task :run
18:10:38.686 [main] INFO de.bkgk.Services.VertRepositoryIMP - Creating repository.
18:10:38.690 [main] INFO de.bkgk.Services.VertRepositoryIMP - Finalizing repository
18:10:38.928 [main] INFO de.bkgk.Services.VertRepositoryIMP - Creating repository.
18:10:39.151 [main] INFO d.b.C.VMailerConfigurationProperties - Starting VMailer version 0.2.14
18:10:39.151 [main] INFO d.b.C.VMailerConfigurationProperties - Starting configuration: Configpfad=C:\TEMP\VMAILER\vmailer.json
18:10:39.228 [main] INFO d.b.C.VMailerConfigurationProperties - Configuration finalized
18:10:39.245 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.13.Final
18:10:39.262 [main] INFO o.h.v.i.engine.ConfigurationImpl - HV000002: Ignoring XML configuration.
18:10:39.533 [main] INFO de.bkgk.Services.SendEmailImp - Constructing.
18:10:39.534 [main] INFO de.bkgk.BusinessLogicImp - Constructing.
18:10:39.758 [main] INFO de.bkgk.BusinessLogicImp - Constructing.
18:10:39.758 [main] INFO de.bkgk.BusinessLogicImp - Finalizing configuration.
18:10:39.758 [main] INFO de.bkgk.Services.SendEmailImp - Finalizing configuration.
18:10:39.808 [main] INFO de.bkgk.Services.SendEmailImp - ... ready.
18:10:39.808 [main] INFO de.bkgk.BusinessLogicImp - .. ready
18:10:39.844 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
18:10:39.945 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
18:10:39.971 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {5.3.6.Final}
18:10:39.973 [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
18:10:40.164 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
18:10:40.533 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
18:10:41.839 [main] INFO de.bkgk.Services.VertRepositoryIMP - Creating repository.
18:10:41.840 [main] INFO de.bkgk.Services.VertRepositoryIMP - Finalizing repository
18:10:41.840 [main] INFO de.bkgk.Services.VertRepositoryIMP - Creating repository.
18:10:41.842 [main] INFO d.b.C.VMailerConfigurationProperties - Starting VMailer version 0.2.14
18:10:41.842 [main] INFO d.b.C.VMailerConfigurationProperties - Starting configuration: Configpfad=C:\TEMP\VMAILER\vmailer.json
18:10:41.843 [main] INFO d.b.C.VMailerConfigurationProperties - Configuration finalized
18:10:41.845 [main] INFO o.h.v.i.engine.ConfigurationImpl - HV000002: Ignoring XML configuration.
18:10:41.854 [main] INFO de.bkgk.Services.SendEmailImp - Constructing.
18:10:41.854 [main] INFO de.bkgk.BusinessLogicImp - Constructing.
18:10:41.856 [main] INFO de.bkgk.BusinessLogicImp - Constructing.
18:10:41.856 [main] INFO de.bkgk.BusinessLogicImp - Finalizing configuration.
18:10:41.856 [main] INFO de.bkgk.Services.SendEmailImp - Finalizing configuration.
18:10:41.857 [main] INFO de.bkgk.Services.SendEmailImp - ... ready.
18:10:41.857 [main] INFO de.bkgk.BusinessLogicImp - .. ready
18:10:41.876 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Starting...
18:10:41.877 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Start completed.
18:10:41.882 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
18:10:44.628 [main] INFO de.bkgk.Services.DatabaseLoaderImp - ... created:
18:10:44.629 [main] INFO de.bkgk.Services.DatabaseLoaderImp - Found untispfad=C:/BIN/20xx
18:10:44.629 [main] INFO de.bkgk.Services.DatabaseLoaderImp - Found untiscmd=C:/TEMP/VMAILER/Daten/SW16_20190114.gpn
18:10:44.629 [main] INFO de.bkgk.Services.DatabaseLoaderImp - Found batchCMD=C:/TEMP/VMAILER/export.bat; will use batch mode.
18:10:44.629 [main] INFO d.bkgk.Services.LoadFromUntisService - Construction start
18:10:44.629 [main] INFO d.bkgk.Services.LoadFromUntisService - Construction end
18:10:44.631 [main] INFO de.bkgk.Services.SchedulerServiceImp - Starting scheduler service.
18:10:44.631 [main] INFO de.bkgk.Services.SchedulerServiceImp - Finalizing configuration.
18:10:44.632 [main] INFO de.bkgk.Services.SchedulerServiceImp - Scheduling task de.bkgk.Services.LoadFromUntisService@6544899b, starting at PT10S, duration PT15M
18:10:44.635 [main] INFO de.bkgk.Services.SchedulerServiceImp - Scheduling task de.bkgk.Services.SendTagesMailService@62cbc478, starting at PT-3H-10M-44.635S, duration PT30M
18:10:44.635 [main] INFO de.bkgk.Services.SchedulerServiceImp - Scheduling task de.bkgk.Services.SendWochenMailService@512abf25, starting at PT-3H-10M-44.635S, duration PT30M
18:10:44.635 [pool-2-thread-1] INFO d.bkgk.Services.SendTagesMailService - Daily emails not at fridays, saturdays or sundays.
18:10:44.635 [pool-2-thread-2] INFO d.b.Services.SendWochenMailService - Weekly emails only at fridays.
18:10:44.635 [main] INFO de.bkgk.Services.SchedulerServiceImp - Scheduler config updated.
18:10:44.636 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 2912ms. Server Running: http://localhost:80
我的豆子通常具有类似于以下的代码:
// @Singleton
@Context
public class VertRepositoryIMP implements VertRepository {
private static final Logger LOG = LoggerFactory.getLogger(VertRepositoryIMP.class);
@PersistenceContext
private EntityManager entityManager;
public VertRepositoryIMP(@CurrentSession EntityManager entityManager){
LOG.info("Creating repository.");
this.entityManager = entityManager;
}
@Override
@PostConstruct
public void initialze(){
LOG.info("Finalizing repository");
}
因此,我获得了有关构造以及Bean最终准备就绪时的日志条目。
在日志中,您看到一些Singleton被多次创建!甚至创建了两个HikariPool。 我不明白。
所有bean都带有@Singleton
或@Context
注释。他们不应该被重用吗?
这些类中有一件特别的事。 Bean SchedulerServiceImpl
使用TaskScheduler启动三个任务。
可能是原因吗?即用于不同线程的单个bean?