1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.yihu.ehr.common;
- import com.yihu.ehr.common.config.SysConfig;
- import com.yihu.ehr.dbhelper.jdbc.DBHelper;
- import com.yihu.ehr.service.thread.CrawlerSupplyThread;
- import com.yihu.ehr.service.thread.CrawlerThread;
- import com.yihu.ehr.service.thread.StandardUpdateThread;
- import com.yihu.ehr.service.thread.ThreadManage;
- import com.yihu.ehr.util.log.LogUtil;
- import javax.servlet.ServletContextEvent;
- import javax.servlet.ServletContextListener;
- import javax.xml.stream.XMLInputFactory;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Properties;
- /**
- * 项目启动执行
- * add by hzp at 2016-01-25
- */
- public class ApplicationStart implements ServletContextListener {
- private static Properties prop = new Properties();
- @Override
- public void contextInitialized(ServletContextEvent context) {
- try {
- String home = System.getProperty("catalina.home").replace('\\', '/');
- String homeUrl = home.substring(0, home.lastIndexOf('/') + 1);
- dbConfig(homeUrl);
- sslConfig(homeUrl);
- } catch (Exception e) {
- System.out.print(e.getStackTrace().toString());
- LogUtil.error(e.getStackTrace().toString());
- }
- }
- /**
- * 修改微服务连接ssl文件
- *
- * @param homeUrl
- */
- private void sslConfig(String homeUrl) throws Exception {
- InputStream in = this.getClass().getResourceAsStream("/config/http.properties");
- prop.load(in);
- String configPath = this.getClass().getClassLoader().getResource("/").getPath() + "config/http.properties";
- OutputStream fos = new FileOutputStream(configPath);
- String url = homeUrl + "ssl/tomcat.keystore";
- prop.setProperty("sslKeystore", url);
- prop.store(fos, "last update");
- in.close();
- fos.close();
- }
- /**
- * 修改数据库连接字符串
- *
- * @param homeUrl
- */
- private void dbConfig(String homeUrl) throws Exception {
- InputStream in = this.getClass().getResourceAsStream("/config/dbhelper.properties");
- prop.load(in);
- String configPath = this.getClass().getClassLoader().getResource("/").getPath() + "config/dbhelper.properties";
- OutputStream fos = new FileOutputStream(configPath);
- String url = homeUrl + "db/localDB.db";
- prop.setProperty("defaultName", "miniResourceDB");
- prop.setProperty("defaultUri", "jdbc:sqlite://" + url);
- prop.store(fos, "last update");
- in.close();
- fos.close();
- }
- @Override
- public void contextDestroyed(ServletContextEvent context) {
- }
- public static void main(String[] args) {
- System.out.println(520 / 3);
- }
- }
|