ApplicationStart.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.yihu.ehr.common;
  2. import com.yihu.ehr.common.config.SysConfig;
  3. import com.yihu.ehr.dbhelper.jdbc.DBHelper;
  4. import com.yihu.ehr.service.thread.CrawlerSupplyThread;
  5. import com.yihu.ehr.service.thread.CrawlerThread;
  6. import com.yihu.ehr.service.thread.StandardUpdateThread;
  7. import com.yihu.ehr.service.thread.ThreadManage;
  8. import com.yihu.ehr.util.log.LogUtil;
  9. import javax.servlet.ServletContextEvent;
  10. import javax.servlet.ServletContextListener;
  11. import javax.xml.stream.XMLInputFactory;
  12. import java.io.FileOutputStream;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import java.io.OutputStream;
  16. import java.util.Properties;
  17. /**
  18. * 项目启动执行
  19. * add by hzp at 2016-01-25
  20. */
  21. public class ApplicationStart implements ServletContextListener {
  22. private static Properties prop = new Properties();
  23. @Override
  24. public void contextInitialized(ServletContextEvent context) {
  25. try {
  26. String home = System.getProperty("catalina.home").replace('\\', '/');
  27. String homeUrl = home.substring(0, home.lastIndexOf('/') + 1);
  28. dbConfig(homeUrl);
  29. sslConfig(homeUrl);
  30. } catch (Exception e) {
  31. System.out.print(e.getStackTrace().toString());
  32. LogUtil.error(e.getStackTrace().toString());
  33. }
  34. }
  35. /**
  36. * 修改微服务连接ssl文件
  37. *
  38. * @param homeUrl
  39. */
  40. private void sslConfig(String homeUrl) throws Exception {
  41. InputStream in = this.getClass().getResourceAsStream("/config/http.properties");
  42. prop.load(in);
  43. String configPath = this.getClass().getClassLoader().getResource("/").getPath() + "config/http.properties";
  44. OutputStream fos = new FileOutputStream(configPath);
  45. String url = homeUrl + "ssl/tomcat.keystore";
  46. prop.setProperty("sslKeystore", url);
  47. prop.store(fos, "last update");
  48. in.close();
  49. fos.close();
  50. }
  51. /**
  52. * 修改数据库连接字符串
  53. *
  54. * @param homeUrl
  55. */
  56. private void dbConfig(String homeUrl) throws Exception {
  57. InputStream in = this.getClass().getResourceAsStream("/config/dbhelper.properties");
  58. prop.load(in);
  59. String configPath = this.getClass().getClassLoader().getResource("/").getPath() + "config/dbhelper.properties";
  60. OutputStream fos = new FileOutputStream(configPath);
  61. String url = homeUrl + "db/localDB.db";
  62. prop.setProperty("defaultName", "miniResourceDB");
  63. prop.setProperty("defaultUri", "jdbc:sqlite://" + url);
  64. prop.store(fos, "last update");
  65. in.close();
  66. fos.close();
  67. }
  68. @Override
  69. public void contextDestroyed(ServletContextEvent context) {
  70. }
  71. public static void main(String[] args) {
  72. System.out.println(520 / 3);
  73. }
  74. }