From 8f5c84e834fdd03c897e4292bba34fd2f72e839d Mon Sep 17 00:00:00 2001
From: 吴学文 <wuxuewen@wuxuewendeMacBook-Pro.local>
Date: 星期三, 24 七月 2019 22:18:12 +0800
Subject: [PATCH] 修复 提示信息和加载进度不在居中问题
---
java110-db/src/main/java/com/java110/db/DataSourceConfig.java | 78 +++++++++++++++++++++++++++------------
1 files changed, 54 insertions(+), 24 deletions(-)
diff --git a/java110-db/src/main/java/com/java110/db/DataSourceConfig.java b/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
index d65e9b8..159df84 100644
--- a/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
+++ b/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
@@ -1,8 +1,19 @@
package com.java110.db;
+import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import javax.servlet.Filter;
+import javax.sql.DataSource;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
/**
@@ -11,10 +22,10 @@
@Configuration
public class DataSourceConfig {
-// @Autowired
-// private Filter statFilter;
-//
-// private static final String SHARDING_YML_PATH = "dataSource.yml";
+ //@Autowired
+ private Filter statFilter;
+
+ private static final String SHARDING_YML_PATH = "dataSource.yml";
/**
* 鏋勫缓dataSource
@@ -26,8 +37,8 @@
* @throws IOException IO 寮傚父
* @since 1.8
*/
-// @Bean
-// public DataSource dataSource() throws SQLException, IOException {
+ @Bean
+ public DataSource dataSource() throws SQLException, IOException {
// YamlShardingConfiguration config = parse();
// YamlShardingRuleConfiguration rule = config.getShardingRule();
// for (String key : config.getDataSources().keySet()) {
@@ -36,22 +47,41 @@
// }
// return ShardingDataSourceFactory.createDataSource(config.getDataSources(),
// rule.getShardingRuleConfiguration(), config.getConfigMap(), config.getProps());
-// }
-//
-// /**
-// * 瑙f瀽yml
-// *
-// * @return yaml 閰嶇疆鏂囦欢
-// * @throws IOException IO 寮傚父
-// * @throws FileNotFoundException 鏂囦欢鏈彂鐜板紓甯�
-// * @throws UnsupportedEncodingException 涓嶆敮鎸佺紪鐮佸紓甯�
-// */
-// private MasterSlaveDataSourceFactory parse() throws IOException, FileNotFoundException, UnsupportedEncodingException {
-// Resource certResource = new ClassPathResource(SHARDING_YML_PATH);
-// try (
-// InputStreamReader inputStreamReader = new InputStreamReader(certResource.getInputStream(), "UTF-8")
-// ) {
-// return YamlMasterSlaveDataSourceFactory;
-// }
-// }
+
+ return YamlShardingDataSourceFactory.createDataSource(getYmlFile());
+ }
+
+ /**
+ * 瑙f瀽yml
+ *
+ * @return yaml 閰嶇疆鏂囦欢
+ * @throws IOException IO 寮傚父
+ * @throws FileNotFoundException 鏂囦欢鏈彂鐜板紓甯�
+ * @throws UnsupportedEncodingException 涓嶆敮鎸佺紪鐮佸紓甯�
+ */
+ private byte[] getYmlFile() throws IOException {
+ Reader reader = null;
+ InputStream inputStream = null;
+ ByteArrayOutputStream swapStream = null;
+ try {
+ Resource resource = new ClassPathResource(SHARDING_YML_PATH);
+
+ inputStream = resource.getInputStream();
+ swapStream = new ByteArrayOutputStream();
+ byte[] buff = new byte[100];
+ int rc = 0;
+ while ((rc = inputStream.read(buff, 0, 100)) > 0) {
+ swapStream.write(buff, 0, rc);
+ }
+ byte[] in2b = swapStream.toByteArray();
+ return in2b;
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ if (swapStream != null) {
+ swapStream.close();
+ }
+ }
+ }
}
--
Gitblit v1.8.0