我们的SpringBoot项目中使用的第三方jar,需要在我们项目里创建config目录,第三方jar要读取里面的配置文件,但是现在maven打包的,读取的config路径不正确,
具体获取config路径的代码如下:
String configPath = ConfigPathUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath();
最终取的路径
xxx\target\xxx.jar!\BOOT-INF\lib\config.jar!\config\
正确的路径应该是xxx\target\xxx.jar!\BOOT-INF\classes\config
这个问题除了修改第三方jar源码还有其他可解的方式吗?
https://blog.csdn.net/xrq0508/article/details/80050119
百度 springboot 虚拟路径映射
@Configuration
@PropertySource({"classpath:application.yml"})
public class WebConfig implements WebMvcConfigurer {
@Value("${filePath}")
private String resourceLocation;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/info/**").addResourceLocations("file:" + resourceLocation + "/");
registry.addResourceHandler("/.well-known/pki-validation/**").addResourceLocations("file:/usr/valid/");
BilibiliJsonUtil.setFilePath(resourceLocation);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index-2.html");
}
}