New file |
| | |
| | | package com.dy.simRtu202404; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | 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.context.annotation.ComponentScan; |
| | | import org.springframework.context.annotation.FilterType; |
| | | |
| | | @Slf4j |
| | | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) //禁止启动数据库连接池 |
| | | @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.simRtu202404"}, |
| | | excludeFilters = { |
| | | @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { |
| | | com.dy.common.apiDoc.SpringApiConfig.class, //一种排除类的方式 |
| | | com.dy.pipIrrGlobal.config.DingTalk.class |
| | | }), |
| | | @ComponentScan.Filter(type = FilterType.REGEX, pattern = { |
| | | //二种排除类的方式,写正则表达式,需要对目标类的完全限定名完全匹配,否则不生效 |
| | | "com.dy.common.aop..*", |
| | | "com.dy.common.apiDoc..*", |
| | | "com.dy.common.multiDataSource..*", |
| | | "com.dy.common.mybatis..*", |
| | | "com.dy.common.singleDataSource..*", |
| | | "com.dy.common.webFilter..*", |
| | | "com.dy.common.webListener..*", |
| | | "com.dy.pipIrrGlobal.webCtrls..*" |
| | | }) |
| | | } |
| | | ) |
| | | public class PipIrrMwSimulateRtu202404Application implements CommandLineRunner { |
| | | |
| | | public static void main(String[] args) { |
| | | parseArg0(args, 0) ; |
| | | parseArg1(args, 1) ; |
| | | parseArg2(args, 2) ; |
| | | parseArg3(args, 3) ; |
| | | parseArg4(args, 4) ; |
| | | parseArg5(args, 5) ; |
| | | |
| | | new SpringApplicationBuilder(PipIrrMwSimulateRtu202404Application.class) |
| | | .web(WebApplicationType.NONE)//不启动web服务 |
| | | .run(args); |
| | | } |
| | | |
| | | private static void parseArg0(String[] args, int index){ |
| | | if(args != null |
| | | && args.length > index |
| | | && args[index] != null |
| | | && !args[index].trim().equals("")){ |
| | | ServerProperties.rtuAddr = args[index] ;//本模拟器模拟RTU地址 |
| | | log.info("参数1:" + ServerProperties.rtuAddr); |
| | | } |
| | | if(ServerProperties.rtuAddr == null){ |
| | | ServerProperties.rtuAddr = "37142501020100218" ; |
| | | } |
| | | } |
| | | private static void parseArg1(String[] args, int index){ |
| | | if(args != null |
| | | && args.length > index |
| | | && args[index] != null |
| | | && !args[index].trim().equals("")){ |
| | | ServerProperties.icCardAddr = args[index] ;//IC卡地址 |
| | | log.info("参数2:" + ServerProperties.icCardAddr); |
| | | } |
| | | if(ServerProperties.icCardAddr == null){ |
| | | ServerProperties.icCardAddr = "C49A340D" ; |
| | | } |
| | | } |
| | | private static void parseArg2(String[] args, int index){ |
| | | if(args != null |
| | | && args.length > index |
| | | && args[index] != null |
| | | && !args[index].trim().equals("")){ |
| | | ServerProperties.icCardNo = args[index] ;//IC卡编号 |
| | | log.info("参数3:" + ServerProperties.icCardNo); |
| | | } |
| | | if(ServerProperties.icCardNo == null){ |
| | | ServerProperties.icCardNo = "37142501020100257" ; |
| | | } |
| | | } |
| | | private static void parseArg3(String[] args, int index){ |
| | | if(args != null |
| | | && args.length > index |
| | | && args[index] != null |
| | | && !args[index].trim().equals("")){ |
| | | ServerProperties.serverIp = args[index] ;//通信中间件服务端IP |
| | | log.info("参数4:" + ServerProperties.serverIp); |
| | | } |
| | | if(ServerProperties.serverIp == null){ |
| | | ServerProperties.serverIp = "127.0.0.1" ; |
| | | } |
| | | } |
| | | private static void parseArg4(String[] args, int index){ |
| | | if(args != null |
| | | && args.length > index |
| | | && args[index] != null |
| | | && !args[index].trim().equals("")){ |
| | | ServerProperties.serverPort = Integer.parseInt(args[index]) ;//通信中间件服务端端口 |
| | | log.info("参数5:" + ServerProperties.serverPort); |
| | | } |
| | | if(ServerProperties.serverPort == null){ |
| | | ServerProperties.serverPort = 60000 ; |
| | | } |
| | | } |
| | | private static void parseArg5(String[] args, int index){ |
| | | if(args != null |
| | | && args.length > index |
| | | && args[index] != null |
| | | && !args[index].trim().equals("")){ |
| | | ServerProperties.type = Integer.parseInt(args[index]) ;//运行方式 |
| | | log.info("参数6:" + ServerProperties.type); |
| | | } |
| | | if(ServerProperties.type == null){ |
| | | ServerProperties.type = 0 ; |
| | | } |
| | | } |
| | | /** |
| | | * Spring容器启动完成后,执行下面方法 |
| | | * @param args 参数 |
| | | * @throws Exception 异常 |
| | | */ |
| | | @Override |
| | | public void run(String... args) throws Exception { |
| | | try{ |
| | | //等待一下 |
| | | Thread.sleep(500L); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | finally { |
| | | this.startMwSv() ; |
| | | } |
| | | } |
| | | |
| | | private void startMwSv(){ |
| | | if(sv != null){ |
| | | sv.startServer(); |
| | | } |
| | | } |
| | | |
| | | |
| | | private Server sv ; |
| | | |
| | | @Autowired |
| | | public void setSv(Server sv){ |
| | | this.sv = sv ; |
| | | } |
| | | } |