工具类或者注解加载资源

1、ResourceUtils 工具类加载资源

Spring 提供了一个 ResourceUtils 工具类,它支持“classpath:”和“file:”的地址前缀,它能够从指定的地址加载文件资源
File f = ResourceUtils.getFile(“classpath:resources/static/test.txt”);

2、@PropertySource

读取外部资源文件的注解(一般读取配置文件)
@PropertySource(value = “classpath:db.properties”, ignoreResourceNotFound = true)(ignoreResourceNotFound表面忽略未找到的资源 )

猜你喜欢

转载自blog.csdn.net/m0_37179470/article/details/81316923