You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.1 KiB
87 lines
2.1 KiB
package com.dsideal.gw;
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import com.dsideal.gw.Controller.ApiController;
|
|
import com.dsideal.gw.Interceptor.AuthInterceptor;
|
|
import com.dsideal.gw.Util.LogBackLogFactory;
|
|
import com.jfinal.config.*;
|
|
import com.jfinal.kit.PropKit;
|
|
import com.jfinal.server.undertow.UndertowServer;
|
|
import com.jfinal.template.Engine;
|
|
|
|
import java.io.File;
|
|
|
|
public class Start extends JFinalConfig {
|
|
|
|
//配置文件
|
|
public static void main(String[] args) {
|
|
//配置文件
|
|
String configFile = "application_dev.properties";
|
|
String myEnvVar = System.getenv("WORKING_ENV");
|
|
if (myEnvVar != null) {
|
|
configFile = configFile.replace("_dev", "_pro");
|
|
System.out.println("环境变量 WORKING_ENV 的值是: " + myEnvVar);
|
|
} else {
|
|
System.out.println("环境变量 WORKING_ENV 未设置。");
|
|
}
|
|
|
|
PropKit.use(configFile);
|
|
UndertowServer.create(Start.class, "undertow.properties").start();
|
|
}
|
|
|
|
/**
|
|
* 配置常量
|
|
*/
|
|
@Override
|
|
public void configConstant(Constants me) {
|
|
//使用LogBack
|
|
me.setLogFactory(new LogBackLogFactory());
|
|
}
|
|
|
|
/**
|
|
* 配置路由
|
|
*/
|
|
@Override
|
|
public void configRoute(Routes me) {
|
|
//默认页面
|
|
me.add("/", ApiController.class);
|
|
}
|
|
|
|
@Override
|
|
public void configEngine(Engine engine) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void configPlugin(Plugins me) {
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 配置全局拦截器
|
|
*/
|
|
@Override
|
|
public void configInterceptor(Interceptors me) {
|
|
me.addGlobalActionInterceptor(new AuthInterceptor());
|
|
}
|
|
|
|
/**
|
|
* 配置处理器
|
|
*/
|
|
@Override
|
|
public void configHandler(Handlers me) {
|
|
}
|
|
|
|
/**
|
|
* 在jfinal启动完成后马上执行
|
|
*/
|
|
@Override
|
|
public void onStart() {
|
|
//打印 启动Logo
|
|
String path = Start.class.getClassLoader().getResource("logo.txt").getPath();
|
|
File file = new File(path);
|
|
System.out.println(FileUtil.readUtf8String(file));
|
|
}
|
|
}
|