Three Value annotation tricks you should know - Microservice configuration with Spring Boot [05]

preview_player
Показать описание

Learn about 3 uses of the Value annotation in Spring Boot microservices to access your configuration. Learn how to set default values for configuration when you don't have anything in the property file. Also, learn how to specify lists and map values in your property files and access them as the right data structure in your Spring Boot components without having to manually parse them

#JavaBrains #Microservices #SpringBoot #Configuration #Course
Рекомендации по теме
Комментарии
Автор

Real talk. This was EXREMELY helpful and helped me figure out an issue I had trying to run a microservice locally. I’m extremely new to coding and this by default gets a subscribe.

bqing
Автор

Hi Kaushik,


For List : although it gives values as [one, two, three]. If you try to print size of list in request handler method you will get 1
Another hint printing list with multiple values would have looked [one, two, three]. i.e. space after each comma

hello Some static message [Mon, Tue, Wed, Thu, Fri]
vs
hello Some static message [Mon, Tue, Wed, Thu, Fri]


Correction:


I used below property in application.properties
weekdays=Mon, Tue, Wed, Thu, Fri


I had to use following code in Rest Controller:
@Value("#{'${weekdays}'.split(', ')}")
private List<String> days;

System.out.println("Number of Days: "+days.size()); added in request handler method printed size =5
In your example it was still printing size=1

omkarkulkarni
Автор

Excellent, Concise and useful. Thanks

AjayKumar-fdmv
Автор

Kaushik has the art of explaining concepts with super simplicity. Thanks, Kaushik.

tejassontakke
Автор

This was very useful, very understandable, thank you :)

istvanolah
Автор

Thanks Kaushik, gained knowledge on spel 🙌🏻🙌🏻

rdnkmr
Автор

Dear Koushik,
I have a remark and a question.
The remark: I believe that "#{${dbValues}}" can be simplified as "#{$dbValues}", How do you think?
The question: How would you interpret the following declaration:
@Value("#{$env} == "production"? realService:dummyService}")
Thank you a lot for your wonderful tutorials

hyperborean
Автор

hi, thanks for your great tutorials, do you know how to enabled auto run when files are changed? if i go on Settings, all Synchronization section box are selected..

ghury
Автор

I got error when it use
properties file
student.hobbies={indoor: 'reading, writing', outdoor: 'fishing, play'}
and using Controller

Map<String, List<String>> hobbies;
When run application-->
Expression parsing failed; nested exception is EL1043E:(pos 7): Unexpected token. Expected 'rcurly(})' but was 'colon(:)'

somnathroy
Автор

I have watched many if your tutorials, all of them are good. But I get truly shocked by your endorsement of field injection. It is a NO NO, in the world of real test driven development. Constructor injection is the way forward. 🙏🙏

eshgholah
Автор

Please make exception handling with springboot video

kameshnayak
Автор

You are simply amazing... Kaushik. I am a fan and consistent follower of your videos. Very very good for beginners and the basics to be strong. Thanks for your willingness to share and exemplary efforts. God bless you.

PrasannaLakshmi
Автор

Can you please add video on SpEl also..

vaibhavsarje
Автор

Does @Value annotation only work on class with @RestController or @Configuration? I have a regular POJO class that I am trying to use @Value annotation to inject values from application.properties but its always null.

But when I move fields with @Value annotation to @RestController it all suddenly works.... am I missing something?

ohhhgggeeezzz
Автор

Last few lines keeps me engaged and waiting..

nishantkr
Автор

Thanks Kaushik. It's indeed a 'value' addition to my knowledge base. :)

harsha
Автор

You are always the best in explanation, thank you @Kaushik. Can you please create a series of SpEL! Thanks again!

nesreenmohd
Автор

Hi kaushik, how about idea of providing same courses on udemy with some price, so that who so ever want to help can buy the courses also.

howtoed
Автор

Thanks so much! I'm currently doing a ticket about this in work. This is very helpful.

bozhang
Автор

You are Awesome Bro You are A Hero You ROCK THE WORLD BRO YOU ARE SUPER AND THE BEST

mohammedshabbirahmed