获取springboot项目根路径

// 获取项目根路径
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());

这个再Windows下是可以的,但是在Linux (centos7)下是不行的,正确的获取方法:

Resource resource = new ClassPathResource("");
System.out.println(resource.getFile().getAbsolutePath());

猜你喜欢

转载自blog.csdn.net/las723/article/details/89105818