Spring Boot Sping Boot 模拟@PropertySource

du7egjpx  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(79)

我有一个类,我想测试,它是用@PropertySource("file:${resources.properties}")注解的。在测试类中,我已经添加了注解@TestPropertySource(locations = {"classpath:test.properties"})。在www.example.com文件中test.properties我有属性resources.properties=C:/Users/User/Resources.properties。我想改变www.example.com变量的值resources.properties到一个指向类路径的路径,这样测试的执行就不依赖于机器。类似这样:resources.properties=classpath:/Resources.properties。但我不能让它工作。抛出的错误是它找不到文件“org.springframework.beans.factory. BeanFunctionStoreException:SomeFailed to parse configuration class [. Controller]; nested exception is java.io.FileNotFoundException:classpath:\Resources.properties(文件名、目录名或卷标语法不正确)“。
我怎样才能得到它?
问题是:如何在test.properties文件中的变量中添加到类路径的路由?为什么不起作用?resources.properties =classpath:/Resources.properties

1qczuiv0

1qczuiv01#

最后,这个方法成功了:resources.properties=src\\test\\resources\\Resources.properties

相关问题