couldnt resolve placeholder from the config
hey guys. i have this config:
and i have this config:
and the thing is that idk how to tell
@Value
that i want to have a list. bc rn i need to specify an element. intellij suggests me this:
@Value("${bankAccounts[0].iban}")
any help? thx66 Replies
⌛
This post has been reserved for your question.
Hey @bambyzas! 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.
Hint: You dont need to quote IBANS
Try this instead:
wait. do i add tab, or space?
NEVER TAB, spaces only! 😄
thanks LD
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.
u mean like that?
I would add another space in 53 and 54.
but is it even possible to do what i want? i.e. inject a list of objects in my Config class?
crap, still doesnt work
It should, is that the complete Config-class?
Oh, you need getter and setter for the private-field. And you need the
@ConfigurationProperties("xxx")
on that class.on that class
. on which one? on my BankAccountConfig or BankAccount?BankAccountConfig
but i dont understand what to write between quotes
Could you create another namespace before the config bankAccounts?
Maybe empty is ok.
my application.yaml looks like this. im not sure i understand what u mean
I reproduced your problem and it works for me.
so do i need to have
@ConfigurationProperties
annotation?Yes.
I send you my working-example
1 Moment
My main class:
My BankAccountConfig:
My BankAccount:
My Config:
Output:
You realy need the
@EnableConfigurationProperties(BankAccountConfig.class)
!idk man. previously i had
and everything was fine. i didnt even need to have
@EnableConfigurationProperties(BankAccountConfig.class)
@EnableConfigurationProperties(BankAccountConfig.class)
should go to the appconfig. Not the BankAccountConfig
Do you have setter for BankAccounts in BankAccountConfig?idk its a good idea
nope, didnt need it
bc BankAccount is:
No no no, I did not meant the application.yml, I meant the AppConfigClass!
You need to add
@EnableConfigurationProperties(BankAccountConfig.class)
to the application-config-java-class!
I am pretty sure you need the setter. But I guess the setter is automatically generated by the @Setter
annotation.yep
Ok, did you add
@EnableConfigurationProperties(BankAccountConfig.class)
to the application-config-java-class?but i have like 5 config classes. why do i need to add only BankAccountConfig class to my application config java class?
Hm, did you already have a
@EnableConfigurationProperties
in your application-config-java-class?nope. dont have it anywehere
BankAccountConfig
Is not a application-config-java-class by-the-way.i never said it is 😦
Ah ok.
np
but i still dont get it
why cant this work?
why is Spring so against it?
it IS a list of objects
Because bankAccounts are "configuration-properties" and not plain properties.
Only
@EnableConfigurationProperties(BankAccountConfig.class)
allow spring to call the constructor of the class "BankAccount".
The word "ConfigurationProperties" have a very special meaning.ok, but why did the old config versin work?
This works great, do not change that!
i know it works, but i need to change it
You might consider to remove the
@Component
. And you might consider to remove the prefix=
.
Why do you need to change it?i need to separate bank accounts. i want to have two separate lists. smth like this:
i have two banks:
bank1
and bank2
.
and i want to have a list of accounts for each of themoh, I think I got your question wrong the whole time.
doesnt matter. its ok
-_-
and now i need to structure my application.yaml and tweak my BankAccountConfig a little
and idk how to do it properly
This might work
ok. but u see, i have this config
and in the 51st line there are accounts of bank1
id like to separate config and properties by the banks
like in the 41st line
idk if u understood me
haha
In line 43-45 the fields of bank1 do not match the fields in the class
BankAccount
ok, ill show u what i want to achieve
i want to have this application.yml
ah, it is getting clearer.
and in my BankAccountCOnfig i want to have everything like this:
but
@Value("${paymentImport.balticGateway.bank1.bankAccounts}")
doesnt work, because Spring wont (for some reason) accept listAre you sure you could use
@Value
in a class that have the @ConfigurationProperties
annotation?im just showing you pseudocode what i want to do 😄
Can you give an example of two bankacounts in line 7? The configuration looks like there is only one bank-account possible.
"LT516126515919194" for example. doesnt matter tbh. why are you asking?
You wrote this pseudocode: but one iban is a string.
String != List<BankAccount>
huh?
you asked me about 7th line
not 9th
oh, wiat
so the question is still there
I give up, I dont get your question. Maybe someone else can help.
😄
maybe someone else can help me out?
💤
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.