Simple Spring Boot Technical Answers

I hate it when people play I've got a secret!

I was a USAF pilot and people like this were often described as being in the "Secret Squirrel Society". In other words they were little weasels, always trying to plan something good for themselves (A two week flight to Hawaii for instance) and they kept it to themselves so that no one else could take the trip from them.

I've noticed s/w engineers are particularly bad about it.

The secrets go something like this...
you> Hey, has anyone run into this weird problem where the Spring Boot jar won't start???
them> Nope...

So I thought I'd provide some of the simple answers I've found.


When you migrate from Spring Boot 2.x to Spring Boot 2.5.x+ the start of the app may fail due to the fact after Spring Boot 2.5, the architecture creates two jar files, rather than one. This confuses gradle a bit (I can't speak for maven) as to which jar to start and as a result your app won't start.

The solution is to add a jars closure like this and it will fix your issue:

jar { enabled = false }

This will prevent the creation of the additional jar and you'll be good.

Another secret is how to fix Spring Boot startup failures when using Swagger.
This one took the author a bit of time to fix but the solution is simple. Just audit your application.yml or application.properties as below and your problem should be solved.
This is currently working with Spring Boot 2.7.0 and Springfox Boot Starter 3.0.0


spring:
    mvc:
        pathmatch:
            matching-strategy:
ANT_PATH_MATCHER

 This fixes the different matching strategies between Spring Boot and Swagger.

 

This secret is a bit more common known but I think it's better than the standard show-sql option in the configuration files. This allows you to format the Hibernate/JPA sql statements and even add comments

spring:
    jpa:
        properties:
            hibernate:

                '[show_sql]': true
                 '[format_sql]': true
              '[use_sql_comments]': true

It's not strictly necessary to quote the properties but that's the way I learned it so...

Sometimes I get a bit confused about what Spring Boot is actually reading from my properties files, especially because it can pick properties up from the system also and inherited sources. The Spring people have thought of this and provided a solution.

You'll need the following dependency in your gradle or maven file:

implementation 'org.springframework.boot:spring-boot-actuator

Then set this value in your configuration file. Here I'm using a yaml file.

management:
  endpoints:
    web:
      exposure:
        include:
          - env
          - health

Standby! More to come!

Comments

Popular posts from this blog

Back To Technology Discussions

Spring Boot Technical Discussions - Pt 2