liurunyu
4 天以前 1cf88d43994ec7ec403319032a9d118b39fe3571
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ConfigXml4Springboot.java
New file
@@ -0,0 +1,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) ;
   }
}