All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yuxuan66.core.Flash Maven / Gradle / Ivy

package com.yuxuan66.core;

import java.net.InetSocketAddress;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;

import com.yuxuan66.core.config.FlashConfig;
import com.yuxuan66.core.config.impl.SimpleFlashConfig;
import com.yuxuan66.core.constant.Constant;
import com.yuxuan66.core.exception.FlashSysException;
import com.yuxuan66.core.handler.RequestHandler;
import com.yuxuan66.core.init.InitSystem;
import com.yuxuan66.core.utils.CacheManager;

import lombok.extern.slf4j.Slf4j;

@Slf4j
/**
 * 
 * @ClassName: Flash 
* @Description:(flash框架核心工具)
* @author Sir丶雨轩
* @date 2018年8月9日 下午3:47:58
* */ public final class Flash { private Flash() { } /** * * @Title: startByPackage
* @Description: (通过指定扫描包的方式启动 默认端口:80)
* @author Sir丶雨轩
* @param scanPackage 扫描包名 */ public static void startByPackage(String scanPackage) { startByPackage(scanPackage, 80); } /** * * @Title: startByPackage
* @Description: (通过指定扫描包的方式启动 )
* @author Sir丶雨轩
* @param scanPackage 扫描包名 * @param port 端口 */ public static void startByPackage(String scanPackage, int port) { CacheManager.setData(Constant.CACHE_CONFIGCLASS, new SimpleFlashConfig(scanPackage), 0); start(null, port); } /** * * @Title: start
* @Description: (通过指定配置文件形式启动 端口默认:80)
* @author Sir丶雨轩
* @param config 配置文件类 */ public static void start(Class config) { start(config, 80); } /** * * @Title: start
* @Description: (通过指定配置文件形式启动)
* @author Sir丶雨轩
* @param config 配置文件类 * @param port 端口 */ public static void start(Class config, int port) { long startTime = System.currentTimeMillis(); if (config == null && CacheManager.getData(Constant.CACHE_CONFIGCLASS) == null) { throw new FlashSysException("服务器启动失败,缺少配置文件"); } if (config != null) CacheManager.setData(Constant.CACHE_CONFIGCLASS, config, 0); InetSocketAddress address = new InetSocketAddress("127.0.0.1", port); Server server = new Server(address); ResourceHandler resourceHandler = new ResourceHandler(); // 静态资源处理的handler resourceHandler.setDirectoriesListed(true); // 会显示一个列表 resourceHandler.setResourceBase("src/main/webapp"); HandlerList list = new HandlerList(); list.setHandlers(new Handler[] { new RequestHandler(), resourceHandler }); server.setHandler(list); try { server.start(); } catch (Exception e) { throw new FlashSysException("服务器启动失败", e); } new InitSystem().init(); log.info("Flash Start Success... Port:{} ms:{}", port, System.currentTimeMillis() - startTime); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy