Skip to content

SpringBoot

References


Spring Boot Project Folder Structure

└── MyJavaProject
    ├── src
       ├── main
          ├── java
             └── com.jd.blog
                 └── bootstrap
                 └── config
                 └── conroller
                 └── entity
                 └── exception
                 └── payload
                 └── repository
                 └── security
                 └── service
                     └── impl
                  └── utils
          └── resources
              └── application.properties
          
              
       └── test
           ├── java
              └── com
                  └── example
                      └── MyApplicationTest.java
           └── resources
               └── test.properties
    ├── target
       ├── classes
          └── com
              └── example
                  └── MyApplication.class
       └── test-classes
           └── com
               └── example
                   └── MyApplicationTest.class
    ├── pom.xml
    └── README.md

Featrues

https://www.baeldung.com/spring-boot-custom-banners https://www.baeldung.com/spring-boot-color-banner

Disable H2 in Spring Boot Test

  • Disable H2 DB `@AutoConfigurationTestDataBase(replace = AutoConfigurationTestDatabase.Replace.NONE) image

Actuator Implementation

All annotation

DTO Pattern

How to follow good coding standards in Spring Boot

https://levelup.gitconnected.com/how-to-follow-good-coding-standards-in-spring-boot-a22dd735e3ec

How to call Spring Boot Rest API’s Concurrently

https://levelup.gitconnected.com/how-to-call-spring-boot-rest-apis-concurrently-e23f93448d25

Hikari configuration in Spring boot

Flyway Migration

Using Filters in Spring Web Applications

Scheduling in Spring Boot

MySQL Stored Procedures with Spring Boot

Approach 1 – @NamedStoredProcedureQuery Annotation

Approach-2 @Procedure Annotation

CREATE PROCEDURE 'GET_TOTAL_BLOGS_BY_TITLE' (IN title_in VARCHAR(50), OUT count_out INT)
BEGIN
 SELECT COUNT(*) into count_out from blog WHERE title = title_in;
END
@Repository
public interface BlogRepository extends JpaRepository<Blog,Integer> {

    @Procedure
    int GET_TOTAL_BLOGS_BY_TITLE(String title);

    @Procedure("GET_TOTAL_BLOGS_BY_TITLE")
    int getTotalBlogsByTitle(String title);

    @Procedure(procedureName = "GET_TOTAL_BLOGS_BY_TITLE")
    int getTotalBlogsByTitleProcedureName(String model);

    @Procedure(value = "GET_TOTAL_BLOGS_BY_TITLE")
    int getTotalBlogsByTitleValue(String model);

    @Procedure(name = "Blog.getTotalBlogsByTitleEntiy")
    int getTotalBlogsByTitleEntiy(@Param("model_in") String model);



}
@Service
public class BlogService {
    @Autowired
    private BlogRepository blogRepository;

    public int getTotalBlogsByTitle(String title) {
        return blogRepository.getTotalBlogsByTitle(title);
    }

    public int getTotalBlogsByTitleProcedureName(String title) {
        return blogRepository.getTotalBlogsByTitleProcedureName(title);
    }

    public int getTotalBlogsByTitleValue(String title) {
        return blogRepository.getTotalBlogsByTitleValue(title);
    }

    public int getTotalBlogsByTitleExplicit(String title) {
        return blogRepository.GET_TOTAL_BLOGS_BY_TITLE(title);
    }

    public int getTotalBlogsByTitleEntity(String title) {
        return blogRepository.getTotalBlogsByTitleEntiy(title);
    }

}

Spring Boot Caching


Utility

Lombok

https://howtodoinjava.com/?s=lombok https://www.baeldung.com/?s=lombok

Flyway

https://medium.com/javarevisited/database-migration-in-spring-boot-using-flyway-ee791db8aea0

Java Tools

Java Faker API

Mapper

Model Mapper

<http://modelmapper.org/>
    private Post mapToEntity(PostDto postDto) {
        Post post = mapper.map(postDto,Post.class);
        return post;
    }

mapstruct

@Mapper 1
public interface CarMapper {

    CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); 3

    @Mapping(source = "numberOfSeats", target = "seatCount")
    CarDto carToCarDto(Car car); 2
}

@Test
public void shouldMapCarToDto() {
    //given
    Car car = new Car( "Morris", 5, CarType.SEDAN );

    //when
    CarDto carDto = CarMapper.INSTANCE.carToCarDto( car );

    //then
    assertThat( carDto ).isNotNull();
    assertThat( carDto.getMake() ).isEqualTo( "Morris" );
    assertThat( carDto.getSeatCount() ).isEqualTo( 5 );
    assertThat( carDto.getType() ).isEqualTo( "SEDAN" );
}