emis-backend/emis-server/src/main/java/com/xdadan/erp/LaunchApplication.java
2025-02-22 16:44:59 +08:00

88 lines
3.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.xdadan.erp;
import com.xdadan.erp.common.utils.PropertyUtil;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.io.File;
/**
* 启动程序
*
* @author xdadan
*/
@EnableScheduling
// 开启缓存
@EnableCaching
@EnableAsync
@ServletComponentScan("com.xdadan.erp.framework.security.filter")
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class LaunchApplication extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception {
initByLocal(args);
}
/**
* 通过本地配置文件运行
* @param args
*/
private static void initByLocal(String[] args){
String configFile = "";
try {
File directory = new File(".");
System.out.println(directory.getCanonicalPath());
System.out.println(directory.getAbsolutePath());
configFile = PropertyUtil.getPropertyValue("config.properties", "config.file");
System.out.println("use config file:" + configFile);
} catch (Exception e) {
e.printStackTrace();
}
ConfigurableApplicationContext context =
new SpringApplicationBuilder(
LaunchApplication.class)
.properties("spring.config.location=" + configFile)
.web(WebApplicationType.SERVLET).run(args);
Environment env = context.getEnvironment();
String serverPort = env.getProperty("server.port");
String contextPath = env.getProperty("server.servlet.context-path", "");
System.out.println("\n\n==>系统启动成功!server.port=" + serverPort + " context-path=" + contextPath);
}
// @Override
// public void onStartup(ServletContext servletContext) throws ServletException {
// super.onStartup(servletContext);
// servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
// SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
// sessionCookieConfig.setHttpOnly(true);
// }
// @Bean
// public DefaultWebSessionManager sessionManager() {
// DefaultWebSessionManager defaultWebSessionManager = new DefaultWebSessionManager();
// defaultWebSessionManager.setGlobalSessionTimeout(60 * 30 * 1000);
// defaultWebSessionManager.setDeleteInvalidSessions(true);
// defaultWebSessionManager.setSessionValidationSchedulerEnabled(true);
// defaultWebSessionManager.setSessionIdCookieEnabled(true);
// // tomcat的JESSIONID自动生成模块
// defaultWebSessionManager.setSessionIdUrlRewritingEnabled(false);
// return defaultWebSessionManager;
// }
}