コード例 #1
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
  public static void contextInitialized(ServletContextEvent sce) {
    contextPath = sce.getServletContext().getContextPath();
    log.info("启动【" + PropertyHolder.getProperty("app.name") + "】");
    log.info("Launch【" + PropertyHolder.getProperty("app.name") + "】", Locale.ENGLISH);
    log.info("应用上下文:" + contextPath);
    log.info("App context:" + contextPath, Locale.ENGLISH);
    ServletContext sc = sce.getServletContext();
    basePath = sc.getRealPath("/");
    if (!basePath.endsWith(File.separator)) {
      basePath = basePath + File.separator;
    }
    // 整个系统中的文件操作都以basePath为基础
    FileUtils.setBasePath(basePath);
    log.info("basePath:" + basePath);
    String userDir = System.getProperty("user.dir");
    log.info("user.dir:" + userDir);
    userDir = FileUtils.getAbsolutePath("/WEB-INF/classes/data/");
    System.setProperty("user.dir", userDir);
    log.info("将user.dir重新设置为:" + userDir);
    log.info("Reset user directory:" + userDir, Locale.ENGLISH);

    String encoding = System.getProperty("file.encoding");
    log.info("你的操作系统所用的编码file.encoding:" + encoding);
    log.info("Encoding of your OS is file.encoding:" + encoding, Locale.ENGLISH);

    // 为spring的配置做预处理
    prepareForSpring();
    // 注册模块
    registerModules();
    // 解析所有的dic.xml文件,并生成供客户端EXT JS调用的文件
    DictionaryGenerator.generateDic(basePath);

    if (runingMonitor) {
      log.info("记录服务器启动日志");
      log.info("Recording the server boot logging", Locale.ENGLISH);
      runingTime = new RuningTime();
      try {
        runingTime.setServerIP(InetAddress.getLocalHost().getHostAddress());
      } catch (UnknownHostException e) {
        log.error("记录服务器启动日志出错", e);
        log.error("Failed to record the server boot logging", e, Locale.ENGLISH);
      }
      runingTime.setAppName(contextPath);
      runingTime.setOsName(System.getProperty("os.name"));
      runingTime.setOsVersion(System.getProperty("os.version"));
      runingTime.setOsArch(System.getProperty("os.arch"));
      runingTime.setJvmName(System.getProperty("java.vm.name"));
      runingTime.setJvmVersion(System.getProperty("java.vm.version"));
      runingTime.setJvmVendor(System.getProperty("java.vm.vendor"));
      runingTime.setStartupTime(new Date());
    }
    if (memoryMonitor) {
      log.info("启动内存监视线程");
      log.info("Enable memory monitor thread", Locale.ENGLISH);
      int circle = PropertyHolder.getIntProperty("monitor.memory.circle");
      memoryMonitorThread = new MemoryMonitorThread(circle);
      memoryMonitorThread.start();
    }
    running = true;
  }
コード例 #2
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
 public static void prepareForSpring() {
   // 供spring扫描组件用
   String basePackage = PropertyHolder.getProperty("basePackages");
   String localBasePackage = PropertyHolder.getProperty("basePackages.local");
   if (localBasePackage != null && !"".equals(localBasePackage.trim())) {
     basePackage = basePackage + "," + localBasePackage;
   }
   System.setProperty("basePackage", basePackage);
 }
コード例 #3
0
ファイル: SystemListener.java プロジェクト: njcharran/APDPlat
 private static void registerModules() {
   StringBuilder modules = new StringBuilder();
   try {
     Enumeration<URL> ps =
         Thread.currentThread()
             .getContextClassLoader()
             .getResources("META-INF/services/module.xml");
     while (ps.hasMoreElements()) {
       URL url = ps.nextElement();
       String file = url.getFile();
       if (file.contains(".jar!")) {
         int start = file.indexOf("WEB-INF/lib/");
         int end = file.indexOf("!/META-INF/services/module.xml");
         if (start == -1 || end == -1) {
           continue;
         }
         String jar = file.substring(start, end);
         modules.append(jar).append(",");
         log.info("注册模块:" + jar);
         log.info("Register module:" + jar, Locale.ENGLISH);
         extractWebFromModule(jar);
         extractDataFromModule(jar);
       } else {
         log.warn("在非jar包中找到META-INF/services/module.xml");
         log.warn("Find META-INF/services/module.xml in non-jar", Locale.ENGLISH);
       }
     }
   } catch (IOException e) {
     log.error("注册模块出错", e);
     log.error("Failed to register module", e, Locale.ENGLISH);
   }
   if (modules.length() > 0) {
     modules = modules.deleteCharAt(modules.length() - 1);
   }
   // 从配置文件中获取属性
   String scanJars = PropertyHolder.getProperty("scan.jars");
   log.info("注册模块前,scanJars: " + scanJars);
   log.info("Before register,scanJars: " + scanJars, Locale.ENGLISH);
   if (scanJars != null && !"".equals(scanJars.trim())) {
     scanJars = scanJars + "," + modules.toString();
   } else {
     scanJars = modules.toString();
   }
   // 设置到系统属性中
   // spring会把系统属性中的配置覆盖掉配置文件中的配置
   // <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
   System.setProperty("scan.jars", scanJars);
   // 设置回配置属性
   PropertyHolder.setProperty("scan.jars", scanJars);
   log.info("注册模块后,scanJars: " + scanJars);
   log.info("After register,scanJars: " + scanJars, Locale.ENGLISH);
 }
コード例 #4
0
 private boolean isSubPackagesEnabled(PropertyHolder propertyHolder) {
   return isTrue(propertyHolder.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES));
 }