【更新】修复连接池未释放的一个bug

pull/110/MERGE
xuyuxiang 2023-05-29 14:13:58 +08:00
parent 8459e94215
commit 47623533bd
1 changed files with 21 additions and 13 deletions

View File

@ -48,6 +48,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
@ -75,6 +76,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
@ -509,7 +511,10 @@ public class GlobalConfigure implements WebMvcConfigurer {
@Override @Override
public String getDatabaseId(DataSource dataSource) throws SQLException { public String getDatabaseId(DataSource dataSource) throws SQLException {
String url = dataSource.getConnection().getMetaData().getURL().toLowerCase(); Connection conn = null;
try {
conn = dataSource.getConnection();
String url = conn.getMetaData().getURL().toLowerCase();
if (url.contains("jdbc:oracle")) { if (url.contains("jdbc:oracle")) {
return "oracle"; return "oracle";
} else if (url.contains("jdbc:postgresql")) { } else if (url.contains("jdbc:postgresql")) {
@ -523,6 +528,9 @@ public class GlobalConfigure implements WebMvcConfigurer {
} else { } else {
return "mysql"; return "mysql";
} }
} finally {
JdbcUtils.closeConnection(conn);
}
} }
} }