spring-boot - 在 Spring Boot 中将更改日志文件添加到类路径
问题描述
在我的 Spring Boot 项目中,我有一个读取CHANGELOG.md
文件内容的端点。我想从类路径中读取我的 CHANGELOG 文件,因为我的代码中有这样的内容:
ClassPathResource myChangeLogFile = new ClassPathResource("CHANGELOG.MD");
解决方案
您必须将其包含在生成的 JAR 文件中,或者将其放在默认包含在类路径中的目录中(例如 src/main/resources)。
要包含在 JAR 文件中,您可以执行以下操作:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>CHANGELOG.md</file>
<type>md</type>
<classifier>changelog</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
推荐阅读
- git - git branch -r --merged 不显示合并的分支
- javascript - Promises Sequencing
- c# - 使用 zkemkeeper.dll 进行访问控制,但不使用 #application.for zkteco c3-100 设备解锁
- spring-boot - 使用枚举过滤状态
- pytorch - 在每一行中选择/屏蔽不同的列索引
- linux - 在 Alt push 上 Manjaro Xfce 中基于电子的应用程序中的焦点丢失
- android - 从 ArrayAdapter 中的项目从 ListView 更改为 DetailView
- flutter - 从颤动的图像选择器中选择图像后,如何在图像上实现删除图标?
- c++ - Can't recolor edges in vtk
- javascript - designing three dimensional relationships with ORM (TypeORM)