| New file | 
|  |  |  | 
|---|
|  |  |  | 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) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|