Saturday, December 21, 2019

Continues Integration Testing With CircleCI


·       It’s very easy to configure CircleCI to use your maven project.
·       Once done whenever you push anything to repository the CircleCI will automatically build your project running your test cases to make sure nothing breaks in this build.

Steps
1. Go to below web site
2. Click on Go to app.
3. Click on Add Projects
4. Click on “Set up Project” button next to your github project.
5. Choose Linux , Maven (Java) and copy .yml file contents.
6. In your project at root , create a file like .circleci/config.yml and past the previously copied content to this file.
7.  Now commit and push your project to gihub so that CircleCI can read the current changes.
8. Go back to your CircleCIà Add ProjectsàYour project page and press start Building. CircleCI will now build your maven project and if everything goes ok it will show you success message.
9. If not it will send you an error email message.
10.         You can also view the complete error stack trace at CircleCi website.
11.         Now whenever you commit and push any changes to your github project CircleCI will automatically build your project and if there is any error it will inform you about it.

12.         You can also add the status badge from CircleCI to your github reporsitory page , it’s an easy step please google about it.

13.         Once you have CircleCI configured , go to your commits in github and you will see a green tick against your commits which basically tells you that the build was successful after this commit. Like below


·       






   

Sunday, December 8, 2019

Using Project Lomobok in Spring and JPA

   What is Project Lomobok
Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.

How to Configure
  • Go to https://projectlombok.org/mavenrepo/
  • Copy latest dependency for this project and paste into your project’s pom.xml
  • Let intelij (Or your preferd IDE) download the dependency
  • Enable lombok plugin in intelij

How To Use
  •    Open a bean
  •     Refactor à Lombok as @Data and notice the code getting refactored.
  • What does @Data do while using Lombo
o   It adds
§  Getters and setters
§  HashCode
§  Equals
Some Tips For Using LOMBOK and JPA
  •   /**

 * Having bydirectional relationshps in a n entity and using lambok with it creates
        problem for hashcoding so we will have to exclude the bidirectional
 memebers of this class

 * while using lombokl

 */

@EqualsAndHashCode(exclude = "recipes")
 
  •  Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.spring5.springrecepie.domain.Category.recipes, could not initialize proxy - no Session

  • The above error was caused when there was no “fetch = FetchType.EAGER” defined 
  • Hence defining mapping as below resolved this problem
·       @ManyToMany(mappedBy = "categories",fetch = FetchType.EAGER)
private Set<Recipe> recipes;

Lombok Features And Annotations

  •   /*Lombok Annotations*/
    @Setter
    @Getter
    @EqualsAndHashCode
    (exclude = {"petType","owner","visitSet"})
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    /*Lombok Annotations*/
  • Visit below page to see all the available features

Video Tutorial
  •  Also you can watch the video given on below URL