From 2882d700cc2a21c581b7fb1299b8bd8ecbd2635f Mon Sep 17 00:00:00 2001 From: 6092002067 Date: Sat, 18 Feb 2017 14:38:29 +0800 Subject: Fix DbDaoUtil.java code Issue-ID:HOLMES-9 Change-Id: Ibc5f4fbefe98d651a977eb27def7983fe98bfdd7 Signed-off-by: youbowu --- .../main/java/org/openo/holmes/common/utils/DbDaoUtil.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'holmes-actions/src') diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java index fcd90aa..b45fb4a 100644 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java @@ -18,10 +18,10 @@ package org.openo.holmes.common.utils; import io.dropwizard.db.DataSourceFactory; import io.dropwizard.jdbi.DBIFactory; import io.dropwizard.setup.Environment; +import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; -import org.glassfish.hk2.api.IterableProvider; import org.jvnet.hk2.annotations.Service; import org.skife.jdbi.v2.DBI; import org.skife.jdbi.v2.Handle; @@ -32,20 +32,19 @@ import org.skife.jdbi.v2.Handle; public class DbDaoUtil { private static DBI jdbi; - @Inject - private static IterableProvider environmentProvider; - + private Environment environmentProvider; @Inject - private static IterableProvider dataSourceFactoryProvider; + private DataSourceFactory dataSourceFactoryProvider; - static { + @PostConstruct + public void init() { if (jdbi == null) { synchronized (DbDaoUtil.class) { if (jdbi == null) { final DBIFactory factory = new DBIFactory(); jdbi = factory - .build(environmentProvider.get(), dataSourceFactoryProvider.get(), "mysql"); + .build(environmentProvider, dataSourceFactoryProvider, "mysql"); } } } -- cgit 1.2.3-korg