Saturday, December 17, 2022

POM File learnings

 - <scope> provided </scope>. in dependency means this is only for dependency

Eg:  Lombok is a compile-only tool, so that we used to provide a scope here for this dependency.

- <scope>test </scope> in depdency section is only test.


spring boot MAVEN Plugin to create a runnable jar automatically for our microservice.

- To read applicatoin.properties from a class 

  •  We will add @ConfiguratoinProperties annotation on the class by adding prefix with value
    • Ex: You have application.yaml in module/resources folder
      • There you provided as
                           Twitter-to-kafka-service:

                                twitter-keywords:

                                - Java

                                 - Microservices

                                 - Spring

                                 - Kafka

        

  • In the class where we want to read the properties file we define as below in class
                @ConfiguratoinProperties(prefix = "twitter-to-kafka-service")
                public class TwitterToKafkaServiceConfigData {
                        private List<String> twitterKeywords;
                        // Please note that 
/*

Then as a private list of string, with name twitterKeywords here.

The naming is important, and this should match to the definition and the application YAML file

Note that for twitter-keywords, we use twitterKeywords with capital, "K" so for replacement of. "-K" we use "Capital K".


*/
                }
                
  • To make that class as a Spring Bean, we will add @Configuration Annotation.
               
                @Configuration
                @ConfiguratoinProperties(prefix = "twitter-to-kafka-service")
                public class TwitterToKafkaServiceConfigData {
                        private List<String> twitterKeywords;
                        // Please note that 

  • We will also use @Data  annotation from Lombok here to obtain methods like getter, setter , hashcode  and toString to get rid of some boilerplate JAVA codes.

    So what Lombok does is to create some code like getter setter methods and then update the class with these methods.                

                 
                @Data 
                @Configuration
                @ConfiguratoinProperties(prefix = "twitter-to-kafka-service")
                public class TwitterToKafkaServiceConfigData {
                        private List<String> twitterKeywords;
                        // Please note that 
   

No comments:

Post a Comment