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
package com.dy.common.util;
 
import java.net.URL;
import org.jdom2.Document;
 
@SuppressWarnings("unused")
public class ConfigXmlNoSpringboot extends ConfigXml {
    /**
     * 在非SpringBoot环境中应用
     * 创建Document对象
     * @param clazz 参考类
     * @param filePath 配置文件路径
     * @return 返回结果  返回结果返回 doc对象
     * @throws Exception  抛出异常 抛出异常
     */
    public Document createDom(Class<?> clazz, String filePath) throws Exception {
        if(clazz == null){
            throw new Exception("class对象为空!");
        }
        if(filePath == null || filePath.equals("")){
            throw new Exception("配置文件路径名称为空!");
        }
        if(!filePath.startsWith("/")){
            filePath = "/" + filePath ;
        }
        URL configFileURL = clazz.getResource(filePath);
        if (configFileURL == null) {
            throw new Exception("没有得到" + filePath + "配置!");
        }
        return super.doCreateDom(configFileURL) ;
    }
 
}