1 可以用application.properties中设置参数
2 可以新建一个arguments.properties,往里面配置参数
这两种方式都可以在打成jar包后,直接 --arg=xx 传参数启动jar包
/**
* java -jar xxx-1.0-SNAPSHOT.jar --keyWord=天津
* java -jar xxx-1.0-SNAPSHOT.jar --keyWord=天津,北京,石家庄
* java -jar xxx-1.0-SNAPSHOT.jar //默认keyWord=关键词
*
*/
@Slf4j
@Component
@SpringBootApplication
public class Classesesesss {
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("user.dir"));
File f = new File(this.getClass().getResource("").getPath());
ConfigurableApplicationContext applicationContext = SpringApplication.run(Classssssss.class, args);
SBean sb = (SBean) applicationContext.getBean("spider");
sb.method();
// String MobilePhoneNumber = System.getProperty("MobilePhoneNumber");
// String UserName = System.getProperty("UserName");
// String Password = System.getProperty("Password");
// System.out.println("main()获取到的参数是:"+System.getProperty("KeyWords"));
// String[] KeyWords;
// KeyWords=System.getProperty("KeyWords").split(",");
}
}