Skip to content

Commit 82ed749

Browse files
committed
Update Java version to 21 and improve logging in ServerDetails
Upgraded the project to require Java 21 in `pom.xml` and `README.md`. Replaced Lombok's `@Slf4j` with a manually initialized SLF4J logger in `ServerDetails`, and improved code readability by inlining constants. These changes ensure compatibility and enhance maintainability.
1 parent a3d0ec1 commit 82ed749

File tree

4 files changed

+63
-47
lines changed

4 files changed

+63
-47
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ file on the local file system.
3636
## Prerequisites
3737
Make sure you have installed all the following prerequisites on your development machine:
3838

39-
* **Java 17** - You will need at least Java 17 installed on your machine because it is required by **Spring Boot 3**.
39+
* **Java 21** - You will need at least Java 21 installed on your machine because it is required by **Spring Boot 3**.
4040
If you are using IntelliJ, you can easily download it directly from the IDE.
4141
`File -> Project Structure -> Project -> SDK -> Add SDK -> Download JDK...`. Alternatively, you can download it from
42-
here: [Download & Install Java 17](https://www.oracle.com/java/technologies/downloads/#java17)
42+
here: [Download & Install Java 21](https://www.oracle.com/java/technologies/downloads/#java21)
4343

4444

4545
* **Docker Desktop** - `Integration tests use Testcontainers`, which requires Docker Desktop to be installed and running

openapi-department-api.json

+35-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"openapi" : "3.0.1",
2+
"openapi" : "3.1.0",
33
"info" : {
44
"title" : "Department API",
55
"description" : "Active profile: DEFAULT",
6-
"version" : "2.7.0"
6+
"version" : "2.8.5"
77
},
88
"servers" : [ {
9-
"url" : "http://192.168.1.63:8080/department-api",
9+
"url" : "http://192.168.1.11:8080/department-api",
1010
"description" : "Generated server url"
1111
} ],
1212
"paths" : {
@@ -572,25 +572,25 @@
572572
"components" : {
573573
"schemas" : {
574574
"DepartmentRequestDTO" : {
575-
"required" : [ "departmentCode", "departmentDescription", "departmentName" ],
576575
"type" : "object",
577576
"properties" : {
578577
"departmentCode" : {
578+
"type" : "string",
579579
"maxLength" : 2147483647,
580-
"minLength" : 2,
581-
"type" : "string"
580+
"minLength" : 2
582581
},
583582
"departmentName" : {
583+
"type" : "string",
584584
"maxLength" : 2147483647,
585-
"minLength" : 2,
586-
"type" : "string"
585+
"minLength" : 2
587586
},
588587
"departmentDescription" : {
588+
"type" : "string",
589589
"maxLength" : 2147483647,
590-
"minLength" : 10,
591-
"type" : "string"
590+
"minLength" : 10
592591
}
593-
}
592+
},
593+
"required" : [ "departmentCode", "departmentDescription", "departmentName" ]
594594
},
595595
"APIResponseDepartmentDTO" : {
596596
"type" : "object",
@@ -626,11 +626,11 @@
626626
"type" : "string"
627627
},
628628
"employees" : {
629-
"uniqueItems" : true,
630629
"type" : "array",
631630
"items" : {
632631
"$ref" : "#/components/schemas/EmployeeDTO"
633-
}
632+
},
633+
"uniqueItems" : true
634634
}
635635
}
636636
},
@@ -666,26 +666,26 @@
666666
}
667667
},
668668
"EmployeeRequestDTO" : {
669-
"required" : [ "email", "firstName", "lastName" ],
670669
"type" : "object",
671670
"properties" : {
672671
"firstName" : {
672+
"type" : "string",
673673
"maxLength" : 2147483647,
674-
"minLength" : 2,
675-
"type" : "string"
674+
"minLength" : 2
676675
},
677676
"lastName" : {
677+
"type" : "string",
678678
"maxLength" : 2147483647,
679-
"minLength" : 2,
680-
"type" : "string"
679+
"minLength" : 2
681680
},
682681
"email" : {
683682
"type" : "string"
684683
},
685684
"salary" : {
686685
"type" : "number"
687686
}
688-
}
687+
},
688+
"required" : [ "email", "firstName", "lastName" ]
689689
},
690690
"APIResponseEmployeeDTO" : {
691691
"type" : "object",
@@ -705,7 +705,6 @@
705705
}
706706
},
707707
"EmployeeSearchCriteriaDTO" : {
708-
"required" : [ "page", "size" ],
709708
"type" : "object",
710709
"properties" : {
711710
"firstName" : {
@@ -732,7 +731,8 @@
732731
"$ref" : "#/components/schemas/SortItem"
733732
}
734733
}
735-
}
734+
},
735+
"required" : [ "page", "size" ]
736736
},
737737
"SortItem" : {
738738
"type" : "object",
@@ -798,13 +798,13 @@
798798
"sort" : {
799799
"$ref" : "#/components/schemas/SortObject"
800800
},
801-
"pageable" : {
802-
"$ref" : "#/components/schemas/PageableObject"
803-
},
804801
"numberOfElements" : {
805802
"type" : "integer",
806803
"format" : "int32"
807804
},
805+
"pageable" : {
806+
"$ref" : "#/components/schemas/PageableObject"
807+
},
808808
"empty" : {
809809
"type" : "boolean"
810810
}
@@ -820,6 +820,15 @@
820820
"sort" : {
821821
"$ref" : "#/components/schemas/SortObject"
822822
},
823+
<<<<<<< HEAD
824+
=======
825+
"paged" : {
826+
"type" : "boolean"
827+
},
828+
"unpaged" : {
829+
"type" : "boolean"
830+
},
831+
>>>>>>> 767326b (Update Java version to 21 and improve logging in ServerDetails)
823832
"pageNumber" : {
824833
"type" : "integer",
825834
"format" : "int32"
@@ -851,7 +860,6 @@
851860
}
852861
},
853862
"DepartmentSearchCriteriaDTO" : {
854-
"required" : [ "page", "size" ],
855863
"type" : "object",
856864
"properties" : {
857865
"departmentCode" : {
@@ -878,7 +886,8 @@
878886
"$ref" : "#/components/schemas/SortItem"
879887
}
880888
}
881-
}
889+
},
890+
"required" : [ "page", "size" ]
882891
},
883892
"APIResponsePageDepartmentDTO" : {
884893
"type" : "object",

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description>department-api</description>
1616

1717
<properties>
18-
<java.version>17</java.version>
18+
<java.version>21</java.version>
1919
<org.mapstruct.version>1.6.3</org.mapstruct.version>
2020
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
2121
<springdoc-openapi-starter-webmvc-ui.version>2.8.5</springdoc-openapi-starter-webmvc-ui.version>

src/main/java/com/ainigma100/departmentapi/filter/ServerDetails.java

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.ainigma100.departmentapi.filter;
22

33
import lombok.AllArgsConstructor;
4-
import lombok.extern.slf4j.Slf4j;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
56
import org.springframework.boot.context.event.ApplicationReadyEvent;
67
import org.springframework.context.event.EventListener;
78
import org.springframework.core.env.Environment;
@@ -14,38 +15,44 @@
1415
/**
1516
* Component for logging server details upon application startup.
1617
*
17-
* This class listens for the ApplicationReadyEvent to log important server details such as
18-
* the protocol, host, port, context path, active profiles, and the URL for accessing Swagger UI.
18+
* <p>This class listens for the ApplicationReadyEvent to log important server details such as
19+
* the protocol, host, port, context path, active profiles, and the URL for accessing Swagger UI.</p>
1920
*/
20-
@Slf4j
2121
@AllArgsConstructor
2222
@Component
2323
public class ServerDetails {
2424

25+
private static final Logger log = LoggerFactory.getLogger(ServerDetails.class);
26+
27+
2528
private final Environment environment;
26-
private static final String SERVER_SSL_KEY_STORE = "server.ssl.key-store";
27-
private static final String SERVER_PORT = "server.port";
28-
private static final String SERVER_SERVLET_CONTEXT_PATH = "server.servlet.context-path";
29-
private static final String SPRINGDOC_SWAGGER_UI_PATH = "springdoc.swagger-ui.path";
30-
private static final String DEFAULT_PROFILE = "default";
29+
3130

3231
@EventListener(ApplicationReadyEvent.class)
3332
public void logServerDetails() {
3433

35-
String protocol = Optional.ofNullable(environment.getProperty(SERVER_SSL_KEY_STORE)).map(key -> "https").orElse("http");
34+
String serverSslKeyStore = "server.ssl.key-store";
35+
String serverPortKey = "server.port";
36+
String serverServletContextPath = "server.servlet.context-path";
37+
String springdocSwaggerUiPath = "springdoc.swagger-ui.path";
38+
String defaultProfile = "default";
39+
40+
41+
String protocol = Optional.ofNullable(environment.getProperty(serverSslKeyStore)).map(key -> "https").orElse("http");
3642
String host = getServerIP();
37-
String serverPort = Optional.ofNullable(environment.getProperty(SERVER_PORT)).orElse("8080");
38-
String contextPath = Optional.ofNullable(environment.getProperty(SERVER_SERVLET_CONTEXT_PATH)).orElse("");
43+
String serverPort = Optional.ofNullable(environment.getProperty(serverPortKey)).orElse("8080");
44+
String contextPath = Optional.ofNullable(environment.getProperty(serverServletContextPath)).orElse("");
3945
String[] activeProfiles = Optional.of(environment.getActiveProfiles()).orElse(new String[0]);
40-
String activeProfile = (activeProfiles.length > 0) ? String.join(",", activeProfiles) : DEFAULT_PROFILE;
41-
String swaggerUI = Optional.ofNullable(environment.getProperty(SPRINGDOC_SWAGGER_UI_PATH)).orElse("/swagger-ui/index.html");
46+
String activeProfile = (activeProfiles.length > 0) ? String.join(",", activeProfiles) : defaultProfile;
47+
String swaggerUI = Optional.ofNullable(environment.getProperty(springdocSwaggerUiPath)).orElse("/swagger-ui/index.html");
4248

4349
log.info(
4450
"""
45-
\n
46-
Access Swagger UI URL: {}://{}:{}{}{}
47-
Active Profile: {}
48-
""",
51+
52+
53+
Access Swagger UI URL: {}://{}:{}{}{}
54+
Active Profile: {}
55+
""",
4956
protocol, host, serverPort, contextPath, swaggerUI,
5057
activeProfile
5158
);

0 commit comments

Comments
 (0)