How to make spring boot @Value fields inject the values from properties?
authService contains 2 fields:
both of them are set to null for some reason. any idea why? applicaiton test properties indeed contains the 2 pairs
22 Replies
⌛
This post has been reserved for your question.
Hey @Koblížkáč! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
It only happens in tests?
i think so
Inject a bean of type
Environment
and inspect property sources there.i cant @autowire into tests if you mean that
Wait, the test is not under any Spring context. So
@TestPropertySource
won't work.
Actually you don't even have any Spring beans. Everything is done by Mockito.do i need to use
@springboottest
then? i dont want to load the whole configuratiopn thoughI would inject those values by constructor.
Wdym?
public AuthService(UserService userService, @Value("${notecz.auth.jwt.expire}") Long validFor, @Value("${notecz.auth.jwt.secret}") String secret)
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
it passes null still though
@tjoener sorry for pinging, but i know you knew how my problems could be fixed, do you maybe have an idea why is this happening?
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
still same error
i dont get what you mean by that
Have you provided values for those fields?
i mean they should be loaded from the properties file no?
No
but thats what i want
i dont want to pass them manually
Well, you don't use Spring in this test, so you can't count on its mechanics.
And loading properties from a file is trival, so it's not much of a headache.
what if i wanted to use spring though
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.