Spring boot 打包后 jar文件,IDEA调试时候没什么问题,可是打包成执行jar后发现有异常抛出:

class path resource [1.jpg] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/opt/app.jar!/BOOT-INF/classes!/1.jpg

经实践可用的方法:

  import org.springframework.core.io.ClassPathResource;
  import org.springframework.core.io.Resource;     
  Resource resource = new ClassPathResource("1.jpg");
 //InputStream inputStream = resource.getInputStream();
  Image image = tool.getImage(resource.getURL());

调试、打包都是正常的

spring boot 打包后 jar文件,IDEA调试时候没什么问题,可打包成执行jar后发现有异常抛出:class path resource [1.jpg] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/opt/app.jar!/BOOT-INF/classes!/1.jpg经实践可用的方法: import org.springframe
在项目有读取配置 文件 的地方,项目 打包 jar 后,无法从外部替换默认的配置 文件 ,通过 Spring Boot 一系列的配置可以 解决 该问题。 直接谷歌搜索查到: Spring Boot Executable Jar with Classpath 其中一个 Peter Tarlos 的答案是完整的,本文的内容也是以这里为起点,通过查找官方文档来说明如何实现。 关键的 PropertiesLauncher Executable Jar s Spring Boot ’s executable jar s, their
一、java - jar eureka-0.0.1-SNAPSHOT. jar 为什么可以直接运行? 解压eureka-0.0.1-SNAPSHOT. jar META-INF下的 MANIFEST .MF 文件 内容为: Manifest -Version: 1.0 Implementation-Title: eureka Implementation-Version: 0.0.1-SNAPSHOT Archiv...
项目需要另一个子项目Utils的一个util工具类,在A项目的maven中加入了该子项目 <dependency> <groupId>com.supconit.data.algorithm.platform</groupId> <artifactId>data_algorithm_util</artifactId>
1、group.json为 classpath 目录下的 文件 ,FileCopyUtils为 spring boot 框架自带工具 Resource resource = new ClassPath Resource(“group.json”); byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream()); String con...
1、可 执行 jar 目录结构 在使用 spring - boot -maven-plugin插件 执行 mvn package命令构建可 执行 jar 文件 (Fat JAR )后用“java - jar ”命令就可以直接运行应用程序。 <plugin> <groupId>org. spring framework. boot </groupId> <artifactId>sprin...
在将 Spring Boot 项目打 jar 包后,如果工具类无法读取模板 文件 ,可能是因为模板 文件 没有被正确地 打包 jar 包中。这可以通过以下方法 解决 : 1. 确认模板 文件 的路径和位置。在 Spring Boot 项目中,模板 文件 通常位于/resources/templates目录下。确保 文件 名和相对路径都正确。 2. 使用Maven插件来 打包 项目。例如,在pom.xml 文件 中添加以下配置: <build> <plugins> <plugin> <groupId>org. spring framework. boot </groupId> <artifactId> spring - boot -maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> </plugin> </plugins> </build> 3. 将模板 文件 的位置和路径添加到ResourceLoader中。例如,可以在工具类中使用以下代码来 获取 模板 文件 : ResourceLoader resourceLoader = new FileSystemResourceLoader(); Resource resource = resourceLoader.getResource(" classpath :/templates/template.html"); 其中, classpath :/templates/template.html是模板 文件 的相对路径。 4. 如果仍然无法读取模板 文件 ,可以尝试将模板 文件 打包 jar 包的根目录下。在pom.xml 文件 中添加以下配置: <build> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> <filtering>true</filtering> </resource> </resources> </build> 这将在 打包 时将src/main/resources目录下的所有 文件 打包 到根目录下。 综上所述,将 Spring Boot 项目 打包 jar 包后,如果工具类无法读取模板 文件 ,需要注意模板 文件 的路径和位置,并使用Maven插件来 打包 项目。此外,还可以将模板 文件 打包 jar 包的根目录下。
IFRAME 嵌套报Refused to display ‘http://...‘ in a frame because it set ‘X-Frame-Options‘ to ‘deny‘.解决方式 wdy234: Blocked autofocusing on a <input> element in a cross-origin subframe. 这个问题是跨域 前后端的 域名不一样,iframe 需要全后端 域名一直就行,可以用Nginx 代理或者直接 相同域名 请求就行 Mysql “Too many connections“ 异常 CSDN-Ada助手: 亲爱的博主,非常感谢您的辛勤创作和分享。您的标题“Mysql ‘Too many connections’ 异常”引起了我的极大兴趣,您用简洁而直接的方式表达了这个常见的问题。您的文章无疑为许多人提供了宝贵的解决方案和经验。 在思考您的下一篇可能的创作时,我认为一个潜在的主题是“Mysql性能优化的关键技巧”。考虑到您对Mysql连接问题的深入了解,我相信您有能力进一步探讨如何通过调整参数、使用索引和优化查询等技巧,提高Mysql的性能和吞吐量。 希望这个标题能为您带来一些启发,并继续为我们带来有价值的技术分享。期待在您的博客上看到更多精彩的文章! RabbitMQ Windows安装与启动服务 Bsciology: 你给的erlang版本太高了,跑不起来 @AllArgsConstructor作用 会魔法的小: 启动就报错说找不到WxMpService @AllArgsConstructor作用 会魔法的小: 那怎么解决啊 表情包