一般来说,springboot项目是提供服务的,但是也可以用到导出jar来启动,那么如何介绍参数呢:
package com.example.TestDemo; import com.example.jmeter.bean.TestCaseResult; import com.example.jmeter.controller.JmeterController; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @SpringBootApplication @Slf4j public class JmeterApplication implements ApplicationContextAware { private static ApplicationContext applicationContext; public static void main(String[] args) { SpringApplication.run(JmeterApplication.class, args); JmeterController con=(JmeterController) applicationContext.getBean(JmeterController.class);//获取bean实例 String par=args[0]; switch (par){ case "test1": con.testOneMethod(); break; case "test1": con.testTwoMethod();break; case "test3": con.testThreeMethod(); break; default: TestCaseResult testCaseResult=new TestCaseResult(); testCaseResult.setRunBatch(par); con.keeperJmeterRetry(testCaseResult,args[1]); } } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { JmeterApplication.applicationContext=applicationContext; } }
标签:applicationContext,Springboot,JmeterController,jar,springframework,org,import,ma From: https://www.cnblogs.com/pingguomang/p/18096283