1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.dy.common.util;
 
import java.net.URL;
import org.jdom2.Document;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
 
@SuppressWarnings("unused")
public class ConfigXml4Springboot extends ConfigXml {
 
    /**
     * 在SpringBoot环境中应用
     * @param resourceLoader
     * @param fileName
     * @return
     * @throws Exception
     */
    public Document createDom(ResourceLoader resourceLoader, String fileName) throws Exception {
        if(resourceLoader == null){
            throw new Exception("resourceLoader对象为空!");
        }
        if(fileName == null || fileName.equals("")){
            throw new Exception("配置文件路径名称为空!");
        }
        while(fileName.startsWith("/") || fileName.startsWith("\\")){
            fileName = fileName.substring(1) ;
        }
        Resource resource = resourceLoader.getResource("classpath:" + fileName);
        URL configFileURL = resource.getURL() ;
        if (configFileURL == null) {
            throw new Exception("没有得到" + fileName + "配置!");
        }
        return super.doCreateDom(configFileURL) ;
    }
 
}