Spring Boot simplifies application development with its robust ecosystem, and one hidden gem that can make your experience even smoother is the spring-boot-devtools module. This handy module offers a collection of features specifically designed to enhance developer productivity by streamlining the development workflow.
Key Features of DevTools
Automatic Restart
DevTools monitors your classpath for changes. When it detects modifications, it automatically restarts the application, allowing you to see the effects immediately.LiveReload Integration
With LiveReload, your browser refreshes automatically whenever you make changes to static resources (HTML, CSS, or JavaScript).Environment Customization
DevTools can differentiate between a development and production environment, ensuring features like caching are disabled during development for rapid testing.
Adding DevTools to Your Project
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
To enhance your project with a visually appealing and interactive API documentation, let’s integrate Swagger UI.
implementation("org.springdoc:springdoc-openapi-starter-webmvc-api:2.8.3")
implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.8.3")
The Swagger UI for your application is available at the following URL: http://localhost:8080/webjars/swagger-ui/index.html
@Configuration
public class SwaggerConfig {
@Bean
public GroupedOpenApi inventoryApi() {
return GroupedOpenApi.builder()
.group("Perk-Service")
.displayName("Perk")
.addOpenApiCustomizer(openApi -> openApi.info(new io.swagger.v3.oas.models.info.Info().title("Perk Api for school staff").version("0.0")))
.pathsToMatch("/inventory/**")
.build();
}
}
If you update the OpenAPI configuration in your IntelliJ IDEA code, such as modifying the API title or version:
.addOpenApiCustomizer(openApi -> openApi.info(new io.swagger.v3.oas.models.info.Info().title("Change title").version("0.0")))
.
These changes will not reflect on the Swagger UI even after refreshing the page.
To ensure that changes made in IntelliJ IDEA reflect in your running application (e.g., updates to OpenAPI configurations or other code changes), follow these steps to adjust your IDE settings:
Steps to Apply Settings in IntelliJ IDEA
Open Settings
Go to File > Settings (or IntelliJ IDEA > Preferences on macOS).
In the settings menu, search for Advanced Settings in the search bar.
Under Advanced Settings, find the Compiler section.
Enable Automatic Build:
Allow auto-make to start even if the developer application is currently running.
To ensure that Spring Boot DevTools works seamlessly in IntelliJ IDEA and applies changes dynamically during development, you'll need to adjust an additional setting related to the compiler. Here's how:
Complete Steps to Configure IntelliJ IDEA for DevTools
- Go to File > Settings (or IntelliJ IDEA > Preferences on macOS).
Navigate to Compiler Settings
In the settings menu, go to Build, Execution, Deployment > Compiler.
Enable Build Project Automatically
Apply the Changes
Click Apply and then OK to save your changes.
With the above configurations in place, any changes made to your code—like updating the OpenAPI title or version—will now refresh dynamically in the browser without needing to restart the application manually.
For example, if you modify the OpenAPI customizer:
.addOpenApiCustomizer(openApi ->
openApi.info(new io.swagger.v3.oas.models.info.Info()
.title("Updated API Title")
.version("1.0")
)
)
Top comments (0)