Run a spring boot application with test resources in classpath
Hello,
i try to run a spring boot application with additional classpaths. I want to use some property files for spring which are in the test resource folder. In my src/main/resources are no properties because i add then later with docker-compose (in production).
So if i start the main class (under src/main/java/...), these files are not found (java.io.FileNotFoundException). I hope there is a way to add the src/test/resources folder to the classpath (in the run/debug configuration), so that spring boot will found these classes.
Can you help me?
Thanks Rene
IntelliJ IDEA 2019.3.1 (Ultimate Edition)
Build #IU-193.5662.53, built on December 18, 2019
Licensed to ####################
Subscription is active until ########
Runtime version: 11.0.5+10-b520.17 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.3
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry:
Non-Bundled Plugins: Lombook Plugin, com.dubreuia
Please sign in to leave a comment.
May you say why it is needed to change classpath? There is a standard way to supply custom properties file in Spring Boot:
> java -jar app.jar --spring.config.location=file:///another-location.properties
And you can use this `--spring.config.location` in Program arguments of Run Configuration:
<https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config>
We do not recommend to change classpath at all, but still in case you are sure you need that, you may use one of the following methods at your own risk:
1. Hard - introduce synthetic module that will depend on the main module and include test properties
2. Simple but not reliable - add classes directory dependency to the module using Project structure and use src/test/resources there. (https://i.imgur.com/eupbYlJ.png)