spring boot resources not recognized
hi, i'm using spring boot v3.4.5 in IntelliJ ultimate with a very basic gradle buildscript [1] (no custom paths, no modules, just dependencies and a library as subproject)
now, when running the project using gradle task
bootRun, no resources are ever available, neither by intellij's builtin spring application run configuration
a google search only results in the lie that it should load from src/main/resources path, but it simply does not
i can see the resource files in build/resources and i have tried clean before bootRun as noted by someone on stackoverflow [2], but that also yielded no change whatsoever
i just wish gradle would work as expected just once š
i do not want to build a jar, nor a war or anything like that; i would like to understand why bootRun and intellij's configuration both will not recognize my resources
[1] https://github.com/burdoto/zitrusfalter/blob/main/build.gradle
[2] https://stackoverflow.com/questions/25596783/resource-injection-in-spring-boot-not-working-with-gradle17 Replies
ā This post has been reserved for your question.
Hey @Kaley š¦! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
How do you see these resources not being recognized? Where are they? How are you accessing them?
getResourceAsStream("assets/background.png") always returns null
Can you show the full code?
that method is being called on
Program.class.getResourceAsStream("assets/background.png")
can you change it to
getResourceAsStream("/assets/background.png")?
ok yesare you fr telling me
š
that or
....class.getClassLoader().GetResourceAsStream("assets/background.png")leading slash was the fix, lmfao ffs
if you are looking up resources using that method on a
Class, they are resolved relative to the classthank you very much, the kind of stupid issue
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
with the classloader or a leading slash, it uses the classpath root
so just to make sure i got that right
if the resource would lie at
src/main/resources/de/kaleidox/zitrusfalter/assets/background.png that first call would have worked?
presuming that the package of that class is de.kaleidox.zitrusfalterif that's the package of your main class, yes
yes
gee, alright okay i didnt know that
i work too little with resources lmao
thank you very much!
Post Closed
This post has been closed by <@141476933849448448>.