springboot打包完成之後無法讀取到resources下的資源文件

File privateKeyFile = ResourceUtils.getFile(“classpath:wx.pfx”);
PrivateKey privateKey = getPrivateKey(privateKeyFile , privateKeyPassword);
未打包時都可以獲取到根路徑和文件,打包後報java.lang.NullPointerException

ClassPathResource resource = new ClassPathResource(“wx.pfx”);
InputStream inputStream = resource.getInputStream();
這是因爲打包後Spring試圖訪問文件系統路徑,但無法訪問JAR中的路徑。
因此必須使用resource.getInputStream()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章