1. Overview

If you are spring boot developer then you should know about following things which will improve your productivity as well as product impression. Here are some important spring boot development tips and some important tools and plugin for spring boot application development which will help the developer to best practice for spring boot development.

2. Spring boot tips

Here are very helpful Spring boot tips and tricks which will be helpful to spring boot application development especially starting a new application.

1. Spring boot Dev Tools

  • Spring boot Dev tools are useful while application development. While writing code every time we should build and run the application again and again to check output but Spring boot dev tool provides automatically restart application once the code has been changed.
  • Here we can also exclude some resources where we do not require to restart the application. While packing application for production or staging spring boot will automatically remove the dependency of spring boot dev tools. For spring boot dev tool configuration.

2. Profile-based development

  • Let try to understand the problem first, While developing an application we have multiple environments like Development, Staging, production etc based on our requires those environments have a different-different configuration. for example, each environment has different username and password to connect database.
  • To solve this problem profile based development requires based on profile spring boot will automatically take configuration. How to configure profile based development is available here.

3. Spring boot application database migration

  • Application development not only a one-time process. It’s rapid development. Every time deployment process will not be handled by developers or too much technical person. Database schema changes will be performed frequently based on new feature development and modification of existing features so schema changes will be required.
  • While changes in schema also should be affected in all environments while application will start. We do not like to handle schema changes manually.
  • Spring boot also provides ways to automatically schema updates while application will start,  It just requires .sql files which contains all schema query and schema migration, and other things will be handled by spring boot or schema update and migration plugins which are supported by spring boot. Here is the configuration for database migration
  • Flyway also supports to our write custom Java business logic to migrate our database. Here is an example of Flyway Java Migration Example

4. Spring boot view build information in production or staging

  • While application development we are maintaining proper application version in pom.xml and we should maintain it so we can properly identify our build.
  • But It possible to identify which build currently running on the production server or staging server.  Using endpoints we can check build information in production or staging server. Here is require configuration related to identify build information.

5. Spring boot running application PID

6. Spring boot application set default Timezone

  • Spring boot application(any Java application) will take default timezone as server timezone where the application is running but we do not take a risk that server also is running in our expected timezone. So here is the way to set application default timezone.

7. Spring boot disable command line properties option

  • Spring boot provides ways to give properties option from the command line but sometimes it may create an issue in sense of security so we can also disable command line properties options so if the user tries to pass options from the command line in this case application will not consider those arguments.
  • Enable/Disable command line option is based on our requirement but as a developer, we should know about that application should Enable/Disable command line option. Here is an article related to disabling command line properties option

8. Spring boot provide packaging application of jar/war

  • Spring boot by default generated as .jar file which also contains embedded tomcat. But spring also provides ways to make the bundle of .war file which we can deploy in tomcat manually. Here is Spring boot document to generate war file.

9. Spring boot management endpoints for production

  • We like to know production server on which our application is running, like current memory, remaining memory, health of service, system or OS configuration we can get so many other information using endpoints. We can also provide security to endpoints so no one can directly access those endpoints without a credential.
  • Even custom endpoint also possible based on application requirement. Here is complete document for spring boot management endpoints

10. Spring Boot Rest API Documentation

  • Developer documents are always required specifically working with the team to improve development productivity. We do not like to write a complete document for all services!!
  • Don’t worry. Swagger is with us! Swagger is good API to automatically generate the document for Rest API, We can easily configure with our Spring MVC or Spring boot API. Swagger provides interactive User Interface to work our work easy. We can also test Rest API from there. Here is the complete example of Spring boot Rest API Document using swagger.
Swagger UI Example

Swagger UI Example

3. Conclusion

We have discussed here useful spring boot tips or best practice for spring boot application development. Acceptance of sprig boot best practice will lead us to be professional application developer which differentiates us.

Please give your comments and let’s start discussion

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *