我正在做一个程序,我需要阅读主要的args,但我不知道如何进行。
我的代码
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}控制器
@Controller
public class SampleControler {
@Autowired
private Checker checker;
@RequestMapping("/monitoring")
String home(Model map)
{
try {
map.addAttribute("donnee", checker.run(/*My main args has to be there*/);
return "index" ;
}catch (Exception e) {
return "error";
}
}
}有人能帮忙吗?
发布于 2015-06-12 11:26:14
如手册中所述,您需要添加命令行参数,如
java -jar yourapp.jar --yourParam1=value1 --yourParam2=value2为了你的申请。
在SampleControler中,您可以通过环境访问这些参数
@Controller
public class SampleControler {
@Autowired
private Checker checker;
@Autowired
private Environment environment;
@RequestMapping("/monitoring")
String home(Model map)
{
try {
map.addAttribute("donnee", checker.run(environment.getProperty("yourParam1", "defaultValue"));
return "index" ;
}catch (Exception e) {
return "error";
}
}
}https://stackoverflow.com/questions/30799046
复制相似问题