This module demonstrates how to configure professional-grade documentation for secured APIs and how one Spring Boot application can "talk" to another.
In SwaggerConfig.java, we define a bearerAuth security scheme.
- The "Authorize" Button: This tells Swagger to display a padlock icon in the UI.
- Documentation Only: Note that this doesn't implement JWT security logic (which requires Spring Security), but it documents it so that users know they need to provide a token in the
Authorization: Bearer <token>format.
RestTemplate is a synchronous HTTP client used to consume external REST APIs.
- Config: We define it as a
@BeaninAppConfig.javato make it injectable anywhere in the app. - Usage: In
SpringClientApplication, we use it to reach out to the "Server" service and pull data.
This is a functional interface used to run a piece of code after the Spring application context has fully started. It's perfect for testing clients or seeding data immediately on startup.
- Port:
8080(Default) - Goal: Provides a
/helloendpoint and a Swagger UI that shows how to use Bearer tokens. - Key Class:
SwaggerConfig.java– Uses the modernOpenAPIbean approach to customize API metadata.
- Port:
8081(Configured inapplication.properties) - Goal: Calls the Provider and prints the message to the console.
- Key Class:
HelloWorldClient.java(Logic to call8080/api/hello) andSpringClientApplication.
- Start the Provider: Run
SpringSwaggerConfigApplication.- Visit
http://localhost:8080/swagger-ui/index.htmlto see the "Sample Swagger API Documentation" and the Authorize button.
- Visit
- Start the Consumer: Run
SpringClientApplication. - Observation: Check the console of the Consumer. You will see:
Response from API: Hello WorldThis confirms the two services successfully communicated over the network.
| Component | Role | Why use it? |
|---|---|---|
@SecurityScheme |
Metadata | Tells users the API is protected by JWT. |
RestTemplate |
HTTP Client | Allows Java apps to fetch data from other web services. |
server.port=8081 |
Port Config | Prevents port conflicts when running multiple apps locally. |
@Bean |
Dependency | Decouples the creation of objects (like RestTemplate) from their usage. |
While RestTemplate is the classic choice, Spring now recommends the RestClient (introduced in Spring Boot 3.2/4.x) for synchronous calls or WebClient for reactive, non-blocking calls. Your knowledge of RestTemplate is a perfect foundation for these newer tools!
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.0.1)
2026-01-21T17:07:07.468+05:30 INFO 5836 --- [spring-client] [ restartedMain] c.e.s.SpringClientApplication : Starting SpringClientApplication using Java 25.0.1 with PID 5836 (C:\Users\Hp\IdeaProjects\spring-boot-client-server-swagger-auth\spring-client\target\classes started by Hp in C:\Users\Hp\IdeaProjects\spring-boot-client-server-swagger-auth\spring-client)
2026-01-21T17:07:07.496+05:30 INFO 5836 --- [spring-client] [ restartedMain] c.e.s.SpringClientApplication : No active profile set, falling back to 1 default profile: "default"
2026-01-21T17:07:07.630+05:30 INFO 5836 --- [spring-client] [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2026-01-21T17:07:07.630+05:30 INFO 5836 --- [spring-client] [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2026-01-21T17:07:09.515+05:30 INFO 5836 --- [spring-client] [ restartedMain] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 8081 (http)
2026-01-21T17:07:09.751+05:30 INFO 5836 --- [spring-client] [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2026-01-21T17:07:09.753+05:30 INFO 5836 --- [spring-client] [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.15]
2026-01-21T17:07:10.500+05:30 INFO 5836 --- [spring-client] [ restartedMain] b.w.c.s.WebApplicationContextInitializer : Root WebApplicationContext: initialization completed in 2868 ms
2026-01-21T17:07:11.358+05:30 INFO 5836 --- [spring-client] [ restartedMain] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8081 (http) with context path '/'
2026-01-21T17:07:11.367+05:30 INFO 5836 --- [spring-client] [ restartedMain] c.e.s.SpringClientApplication : Started SpringClientApplication in 4.709 seconds (process running for 5.689)
Response from API: Hello World! 👈 **see here**