浏览代码

SqlMap/sql.xml打包jar后不能正常访问

Signed-off-by: tangsong <86121657@qq.com>
tangsong 1 年之前
父节点
当前提交
432ee9f22d
共有 3 个文件被更改,包括 1362 次插入1340 次删除
  1. 5 0
      pom.xml
  2. 21 4
      src/main/java/com/unis/crk/utils/SqpMapUtil.java
  3. 1336 1336
      src/main/resources/SqlMap/sql.xml

+ 5 - 0
pom.xml

@@ -252,6 +252,11 @@ org.springframework.boot</groupId>-->
252 252
 			</systemPath>
253 253
 		</dependency>
254 254
 		<dependency>
255
+			<groupId>commons-io</groupId>
256
+			<artifactId>commons-io</artifactId>
257
+			<version>2.3</version>
258
+		</dependency>
259
+		<dependency>
255 260
 			<groupId>minio</groupId>
256 261
 			<artifactId>minio</artifactId>
257 262
 			<version>0.6.0.11</version>

+ 21 - 4
src/main/java/com/unis/crk/utils/SqpMapUtil.java

@@ -1,6 +1,7 @@
1 1
 package com.unis.crk.utils;
2 2
 
3
-import org.springframework.core.io.UrlResource;
3
+import cn.hutool.core.io.resource.ClassPathResource;
4
+import org.apache.commons.io.IOUtils;
4 5
 import org.springframework.util.ResourceUtils;
5 6
 
6 7
 import java.io.FileInputStream;
@@ -12,9 +13,10 @@ public class SqpMapUtil {
12 13
 	private final static Map<String, String> SQL_MAP =new LinkedHashMap<>();
13 14
 	static {
14 15
 		try {
15
-			URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
16
-			UrlResource resource1 = new UrlResource(url1);
17
-			Xml xml = new Xml(new FileInputStream(resource1.getFile()));
16
+		    //此种写法在打包jar情况下能正常使用
17
+            URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
18
+			String mapping = IOUtils.toString(url1);
19
+			Xml xml = new Xml(mapping);
18 20
 			Map<String, String> sqls_ = xml.getText();
19 21
 			for (Map.Entry<String, String> entry : sqls_.entrySet()) {
20 22
 				SQL_MAP.put(entry.getKey(), entry.getValue());
@@ -25,6 +27,21 @@ public class SqpMapUtil {
25 27
 		}
26 28
 		
27 29
 	}
30
+//	static {
31
+//		try {
32
+//			URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
33
+//			UrlResource resource1 = new UrlResource(url1);
34
+//			Xml xml = new Xml(new FileInputStream(resource1.getFile()));
35
+//			Map<String, String> sqls_ = xml.getText();
36
+//			for (Map.Entry<String, String> entry : sqls_.entrySet()) {
37
+//				SQL_MAP.put(entry.getKey(), entry.getValue());
38
+//			}
39
+//
40
+//		} catch (Exception e) {
41
+//			e.printStackTrace();
42
+//		}
43
+//
44
+//	}
28 45
 	public static String getSql(String key) {
29 46
 	    return SQL_MAP.get(key);
30 47
 

文件差异内容过多而无法显示
+ 1336 - 1336
src/main/resources/SqlMap/sql.xml