From 7128df991d737d23ee77f89bfe79ec4b79a362df Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Fri, 18 Nov 2016 13:48:45 +0700 Subject: one way for inititialization and finalization: using constructor's initialization or method init() and AutoCloseable inteface and method close() --- .../src/main/java/com/juick/configuration/DataConfiguration.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'juick-server/src/main/java') diff --git a/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java b/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java index 88fc00b3..9f733184 100644 --- a/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java +++ b/juick-server/src/main/java/com/juick/configuration/DataConfiguration.java @@ -1,6 +1,7 @@ package com.juick.configuration; import org.apache.commons.dbcp2.BasicDataSource; +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -13,7 +14,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.TransactionManagementConfigurer; import javax.annotation.Resource; -import javax.sql.DataSource; /** * Created by aalexeev on 11/11/16. @@ -26,8 +26,10 @@ public class DataConfiguration implements TransactionManagementConfigurer { @Resource private Environment env; + // NOTE: The close() method will be called automatically with default @Bean settings + // But Datasource interface has no close() method @Bean - public DataSource dataSource() { + public BasicDataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver")); -- cgit v1.2.3