diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcFactory.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcFactory.java index aa27867..8a10056 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcFactory.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcFactory.java @@ -16,17 +16,19 @@ import xyz.zhouxy.plusone.spring.SpringContextHolder; */ public final class JdbcFactory { - private static final ApplicationContext CONTEXT = SpringContextHolder.getContext(); + private static final ApplicationContext SPRING_APPLICATION_CONTEXT = SpringContextHolder.getContext(); + private static final JdbcTemplate JDBC_TEMPLATE = SPRING_APPLICATION_CONTEXT.getBean(JdbcTemplate.class); + private static final NamedParameterJdbcTemplate NAMED_PARAMETER_JDBC_TEMPLATE = SPRING_APPLICATION_CONTEXT.getBean(NamedParameterJdbcTemplate.class); private JdbcFactory() { throw new IllegalStateException("Utility class"); } public static JdbcTemplate getJdbcTemplate() { - return CONTEXT.getBean(JdbcTemplate.class); + return JDBC_TEMPLATE; } public static NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { - return CONTEXT.getBean(NamedParameterJdbcTemplate.class); + return NAMED_PARAMETER_JDBC_TEMPLATE; } } diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/spring/SpringContextHolder.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/spring/SpringContextHolder.java index 089cee5..b6d4046 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/spring/SpringContextHolder.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/spring/SpringContextHolder.java @@ -4,15 +4,13 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -public class SpringContextHolder { +public enum SpringContextHolder { + + INSTANCE + ; private ApplicationContext context; - private static final SpringContextHolder INSTANCE = new SpringContextHolder(); - - private SpringContextHolder() { - } - public static ApplicationContext getContext() { return INSTANCE.context; }