博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Springboot关于脚本脚本启动的项目:
阅读量:4979 次
发布时间:2019-06-12

本文共 5499 字,大约阅读时间需要 18 分钟。

#!/bin/bash

if [ -f ~/.bash_profile ];
then
  . ~/.bash_profile
fi
JAVA_HOME=/usr/local/usr_software/jdk_1.8.0.121
JRE_HOME=/usr/local/usr_software/jdk_1.8.0.121/jre
MAVEN_HOME=/usr/local/usr_software/maven_3.3.9
REDIS_HOME=/usr/local/usr_software/redis
MYSQL_HOME=/usr/local/usr_software/mysql_5.7.18
NODE_HOME=/usr/local/usr_software/node-v8.2.1-linux-x64
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$MAVEN_HOME/bin:$REDIS_HOME/bin:$MYSQL_HOME/bin:$NODE_HOME/bin:$PATH
export PATH
java -jar /usr/local/usr_application/script/script-1.0.0.jar taskName:MobileAuthTask prop:test >> /dev/null

 

package com.vcredit.script; import com.vcredit.script.exception.InvalidParamException; import com.vcredit.script.model.frame.TaskInfo; import com.vcredit.script.task.Task; import com.vcredit.script.utils.ApplicationContextUtils; import com.vcredit.script.utils.DateUtils; import com.vcredit.script.utils.DdqStringUtils; import lombok.extern.slf4j.Slf4j; import org.slf4j.MDC; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.ImportResource; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.util.ObjectUtils; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Properties; /** * Description:基础应用配置类 * * @author : dfz * Created_Date : 2017-06-05 11:52 */ @Slf4j @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) @ComponentScan(value = { "com.vcredit.*"}) @ImportResource(value = { "classpath*:spring/**/*-config*.xml"}) @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) @EnableTransactionManagement(proxyTargetClass = true) public class Application { public static void main(String[] args) throws IOException { String propName = getPropertiesName(args); startWithProjectProperties(args, propName); log.info("↓"); log.info("╭(●`∀´●)╯ Spring-context loaded ╰(●’◡’●)╮"); log.info("↓"); List
taskInfoList = getTaskInfoList(args); if (taskInfoList != null && taskInfoList.size() > 0) { log.info("任务信息概览 ↓"); log.info("=============================================================================="); log.info("|"); log.info("| 当前时间 : [ {} ] ", DateUtils.dateToString(new Date())); log.info("| 激活配置 : [ {} ] ", propName); log.info("| 任务列表 : [ {} ] ", DdqStringUtils.toString(taskInfoList)); log.info("|"); log.info("=============================================================================="); for (TaskInfo taskInfo : taskInfoList) { new Thread(() -> { try { MDC.put("TRACE_ID", DdqStringUtils.generateDateBasedUUID()); Object task = ApplicationContextUtils.getBean(DdqStringUtils.firstLtrLower(taskInfo.getTaskName())); if (task != null && task instanceof Task) { log.info("任务 : [ {} ] 开始执行..", taskInfo.getTaskName()); ((Task) task).run(taskInfo.getTaskParams()); } else { log.info("任务 : [ {} ] 不存在! 将被跳过..", taskInfo.getTaskName()); } } catch (Exception e) { log.error("任务 : [ {} ] 执行失败.. Exception:", taskInfo.getTaskName(), e); } }).start(); } } else { log.info("未检测到任何任务! 请检查请求参数. 程序即将退出.."); } } // --------------------------------------------------------------------------------------------------- // -------------------------------------↓ Private Methods ↓------------------------------------------- // --------------------------------------------------------------------------------------------------- private static void startWithProjectProperties(String[] args, String propertiesName) throws IOException { Properties properties = new Properties(); InputStream in = Application.class.getClassLoader().getResourceAsStream(propertiesName); properties.load(in); SpringApplication application = new SpringApplication(Application.class); application.setDefaultProperties(properties); application.run(args); } // 获取任务名 private static List
getTaskInfoList(String[] args) { if (ObjectUtils.isEmpty(args)) { return null; } List
resultList = new ArrayList<>(); for (String str : args) { if (str.contains("taskName")) { String[] taskInfoArr = str.split(":"); if (ObjectUtils.isEmpty(taskInfoArr) || taskInfoArr.length != 2) { continue; } List
tmp = parseTaskInfo(taskInfoArr[1]); if (tmp != null) { resultList.addAll(tmp); } } } return resultList; } // 解析任务参数 private static List
parseTaskInfo(String arg) { String[] taskInfoArr = arg.split(","); List
resultList = new ArrayList<>(); for (String taskInfo : taskInfoArr) { String[] tmpArr = taskInfo.split("\\?"); if (ObjectUtils.isEmpty(tmpArr) || DdqStringUtils.isBlank(tmpArr[0])) { throw new InvalidParamException(); } String taskName = tmpArr[0]; String taskParams = tmpArr.length > 1 ? tmpArr[1] : null; resultList.add(new TaskInfo(taskName, taskParams)); } return resultList; } private static String getPropertiesName(String[] args) { String propertiesName = "dev";// 默认dev if (args == null || args.length == 0) { return propertiesName; } for (String str : args) { if (str.contains("prop")) { propertiesName = str.split(":")[1]; } } return "config/" + propertiesName + ".properties"; }}

 

转载于:https://www.cnblogs.com/muliu/p/9491714.html

你可能感兴趣的文章
NOIP2012模拟赛第三弹
查看>>
7.22武汉日全食自拍留念
查看>>
[转帖]mimikatz 学习
查看>>
IIS 使用 HTTP重定向 修改 默认主页
查看>>
教程笔记《JavaScript深入浅出》
查看>>
MySQL——安装
查看>>
【转】移动端常用的四个框架
查看>>
[转载]delete指针之后应该赋值NULL
查看>>
thinkphp3.2导出
查看>>
OO第三阶段总结
查看>>
oracle分页查询
查看>>
windows rap环境搭建
查看>>
找出第3名学生的成绩
查看>>
[转载]typedef常见用法
查看>>
MVC我来了
查看>>
动态期末成绩
查看>>
如何判断用户是否是第一次进入应用程序(仿微信进入动画)
查看>>
2012.12.1 随笔
查看>>
JENKINS 打包发布脚本
查看>>
机器学习基础
查看>>