cRO*_*BOT 0 java spring timestamp properties spring-boot
所以我需要在 app.properties 文件中设置一个文件夹路径名值。我还想以当前时间戳命名它,这样当它用于创建文件时,它也会创建文件夹。我目前拥有的不起作用。
screenshot.events = STARTED,SUCCEEDED,FAILED,STEP
screenshot.path = C:/Automation/${timestamp}
webdriver.type=CHROME
Run Code Online (Sandbox Code Playgroud)
这里有 3 个选项:
您可以在启动 Spring Boot 应用程序时定义所需的 SystemProperty:
public static void main(String[] args) {
System.setProperty("timestamp",String.valueOf(System.currentTimeMillis()));
new SpringApplicationBuilder() //
.sources(Launcher.class)//
.run(args);
}
Run Code Online (Sandbox Code Playgroud)
然后,按照您的方式在 application.properties 中定义您的属性:
screenshot.path = C:/Automation/${timestamp}
Run Code Online (Sandbox Code Playgroud)
@Value("${screenshot.path}")
public void setScreenshotPath(String screenshotPath) {
this.screenshotPath =
screenshotPath.replace("${timestamp}", System.currentTimeMillis());
}
Run Code Online (Sandbox Code Playgroud)
@Value("${screenshot.path}")
private String screenshotPath;
...
new File(screenshotPath.replace("${timestamp}", System.currentTimeMillis());
//or the following without the need for ${timestamp} in screenshot.path
//new File(screenshotPath + System.currentTimeMillis());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2788 次 |
| 最近记录: |