Skip to content

Commit a49f523

Browse files
committed
Enhance service configuration and error handling by adding LoadBalanced annotation, refactoring FeignClient URLs, and improving exception handling in ApiExceptionHandler
1 parent 4f13b62 commit a49f523

File tree

27 files changed

+11185
-600
lines changed

27 files changed

+11185
-600
lines changed

common-lib/effective-pom.xml

Lines changed: 10703 additions & 0 deletions
Large diffs are not rendered by default.

common-lib/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,43 @@
5858
<artifactId>kafka</artifactId>
5959
<scope>test</scope>
6060
</dependency>
61+
<dependency>
62+
<groupId>org.projectlombok</groupId>
63+
<artifactId>lombok</artifactId>
64+
<scope>provided</scope>
65+
</dependency>
6166
</dependencies>
6267

6368
<build>
6469
<plugins>
6570
<plugin>
6671
<groupId>org.apache.maven.plugins</groupId>
6772
<artifactId>maven-compiler-plugin</artifactId>
73+
<version>3.13.0</version>
74+
<configuration>
75+
<source>${java.version}</source>
76+
<target>${java.version}</target>
77+
<annotationProcessorPaths>
78+
<path>
79+
<groupId>org.mapstruct</groupId>
80+
<artifactId>mapstruct-processor</artifactId>
81+
<version>${org.mapstruct.version}</version>
82+
</path>
83+
<path>
84+
<groupId>org.projectlombok</groupId>
85+
<artifactId>lombok</artifactId>
86+
<version>${org.lombok.version}</version>
87+
</path>
88+
<path>
89+
<groupId>org.projectlombok</groupId>
90+
<artifactId>lombok-mapstruct-binding</artifactId>
91+
<version>${lombok-mapstruct-binding.version}</version>
92+
</path>
93+
</annotationProcessorPaths>
94+
<compilerArgs>
95+
<arg>-parameters</arg>
96+
</compilerArgs>
97+
</configuration>
6898
</plugin>
6999
<plugin>
70100
<groupId>org.jacoco</groupId>

common-lib/src/main/java/com/hoangtien2k3/commonlib/exception/ApiExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public ResponseEntity<ErrorVm> handleSignInRequired(SignInRequiredException ex)
150150
}
151151

152152
@ExceptionHandler({Forbidden.class})
153-
public ResponseEntity<ErrorVm> handleForbidden(NotFoundException ex, WebRequest request) {
153+
public ResponseEntity<ErrorVm> handleForbidden(Forbidden ex, WebRequest request) {
154154
HttpStatus status = HttpStatus.FORBIDDEN;
155155
String message = ex.getMessage();
156156

common-lib/src/main/java/com/hoangtien2k3/commonlib/exception/Forbidden.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.hoangtien2k3.commonlib.exception;
22

33
import com.hoangtien2k3.commonlib.utils.MessagesUtils;
4+
import lombok.Setter;
45

6+
@Setter
57
public class Forbidden extends RuntimeException {
68
private String message;
79

@@ -14,7 +16,4 @@ public String getMessage() {
1416
return message;
1517
}
1618

17-
public void setMessage(String message) {
18-
this.message = message;
19-
}
2019
}

common-lib/src/main/java/com/hoangtien2k3/commonlib/utils/AuthenticationUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public static String extractUserId() {
2020
throw new AccessDeniedException(ApiConstant.ACCESS_DENIED);
2121
}
2222

23-
JwtAuthenticationToken contextHolder = (JwtAuthenticationToken) authentication;
23+
if (!(authentication instanceof JwtAuthenticationToken contextHolder)) {
24+
throw new AccessDeniedException(ApiConstant.ACCESS_DENIED);
25+
}
2426

2527
return contextHolder.getToken().getSubject();
2628
}

favourite-service/pom.xml

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,11 @@
1414
<name>favourite-service</name>
1515
<description>Favourite Service</description>
1616
<properties>
17-
<java.version>17</java.version>
18-
<spring-cloud.version>2021.0.8</spring-cloud.version>
1917
<sonar.organization>hoangtien2k3</sonar.organization>
2018
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
2119
</properties>
2220
<dependencies>
23-
<dependency>
24-
<groupId>io.springfox</groupId>
25-
<artifactId>springfox-boot-starter</artifactId>
26-
<version>3.0.0</version>
27-
</dependency>
28-
<dependency>
29-
<groupId>io.springfox</groupId>
30-
<artifactId>springfox-swagger2</artifactId>
31-
<version>3.0.0</version>
32-
</dependency>
33-
<dependency>
34-
<groupId>io.springfox</groupId>
35-
<artifactId>springfox-swagger-ui</artifactId>
36-
<version>3.0.0</version>
37-
</dependency>
21+
3822
<dependency>
3923
<groupId>org.springframework.boot</groupId>
4024
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -47,9 +31,14 @@
4731
<groupId>org.springframework.boot</groupId>
4832
<artifactId>spring-boot-starter-web</artifactId>
4933
</dependency>
34+
<!-- Distributed Tracing -->
5035
<dependency>
51-
<groupId>org.springframework.cloud</groupId>
52-
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
36+
<groupId>io.micrometer</groupId>
37+
<artifactId>micrometer-tracing-bridge-brave</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.zipkin.reporter2</groupId>
41+
<artifactId>zipkin-reporter-brave</artifactId>
5342
</dependency>
5443
<dependency>
5544
<groupId>org.springframework.cloud</groupId>
@@ -83,30 +72,12 @@
8372
<dependency>
8473
<groupId>org.modelmapper</groupId>
8574
<artifactId>modelmapper</artifactId>
86-
<version>2.4.4</version>
87-
</dependency>
88-
<dependency>
89-
<groupId>org.springframework.cloud</groupId>
90-
<artifactId>spring-cloud-starter-sleuth</artifactId>
91-
</dependency>
92-
<dependency>
93-
<groupId>org.springframework.cloud</groupId>
94-
<artifactId>spring-cloud-starter-zipkin</artifactId>
95-
<version>2.2.8.RELEASE</version>
75+
<version>3.2.0</version>
9676
</dependency>
77+
9778
</dependencies>
9879

99-
<dependencyManagement>
100-
<dependencies>
101-
<dependency>
102-
<groupId>org.springframework.cloud</groupId>
103-
<artifactId>spring-cloud-dependencies</artifactId>
104-
<version>${spring-cloud.version}</version>
105-
<type>pom</type>
106-
<scope>import</scope>
107-
</dependency>
108-
</dependencies>
109-
</dependencyManagement>
80+
11081

11182
<build>
11283
<plugins>

inventory-service/pom.xml

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,11 @@
1414
<name>inventory-server</name>
1515
<description>Inventory Server</description>
1616
<properties>
17-
<java.version>17</java.version>
18-
<spring-cloud.version>2021.0.8</spring-cloud.version>
1917
<sonar.organization>hoangtien2k3</sonar.organization>
2018
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
2119
</properties>
2220
<dependencies>
23-
<dependency>
24-
<groupId>io.springfox</groupId>
25-
<artifactId>springfox-boot-starter</artifactId>
26-
<version>3.0.0</version>
27-
</dependency>
28-
<dependency>
29-
<groupId>io.springfox</groupId>
30-
<artifactId>springfox-swagger2</artifactId>
31-
<version>3.0.0</version>
32-
</dependency>
33-
<dependency>
34-
<groupId>io.springfox</groupId>
35-
<artifactId>springfox-swagger-ui</artifactId>
36-
<version>3.0.0</version>
37-
</dependency>
21+
3822
<!-- <dependency>-->
3923
<!-- <groupId>org.liquibase</groupId>-->
4024
<!-- <artifactId>liquibase-core</artifactId>-->
@@ -92,11 +76,7 @@
9276
<version>0.12.5</version>
9377
<scope>compile</scope>
9478
</dependency>
95-
<dependency>
96-
<groupId>org.springframework</groupId>
97-
<artifactId>spring-web</artifactId>
98-
<version>5.3.30</version>
99-
</dependency>
79+
10080
<dependency>
10181
<groupId>io.jsonwebtoken</groupId>
10282
<artifactId>jjwt-api</artifactId>
@@ -116,17 +96,7 @@
11696
</dependency>
11797
</dependencies>
11898

119-
<dependencyManagement>
120-
<dependencies>
121-
<dependency>
122-
<groupId>org.springframework.cloud</groupId>
123-
<artifactId>spring-cloud-dependencies</artifactId>
124-
<version>${spring-cloud.version}</version>
125-
<type>pom</type>
126-
<scope>import</scope>
127-
</dependency>
128-
</dependencies>
129-
</dependencyManagement>
99+
130100

131101
<build>
132102
<plugins>

order-service/pom.xml

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,11 @@
1414
<name>order-service</name>
1515
<description>Order Service</description>
1616
<properties>
17-
<java.version>17</java.version>
18-
<spring-cloud.version>2021.0.8</spring-cloud.version>
1917
<sonar.organization>hoangtien2k3</sonar.organization>
2018
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
2119
</properties>
2220
<dependencies>
23-
<dependency>
24-
<groupId>io.springfox</groupId>
25-
<artifactId>springfox-boot-starter</artifactId>
26-
<version>3.0.0</version>
27-
</dependency>
28-
<dependency>
29-
<groupId>io.springfox</groupId>
30-
<artifactId>springfox-swagger2</artifactId>
31-
<version>3.0.0</version>
32-
</dependency>
33-
<dependency>
34-
<groupId>io.springfox</groupId>
35-
<artifactId>springfox-swagger-ui</artifactId>
36-
<version>3.0.0</version>
37-
</dependency>
21+
3822
<dependency>
3923
<groupId>org.springframework.boot</groupId>
4024
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -65,7 +49,6 @@
6549
<groupId>com.mysql</groupId>
6650
<artifactId>mysql-connector-j</artifactId>
6751
<scope>runtime</scope>
68-
<version>8.2.0</version>
6952
</dependency>
7053
<dependency>
7154
<groupId>org.projectlombok</groupId>
@@ -96,7 +79,7 @@
9679
<dependency>
9780
<groupId>org.modelmapper</groupId>
9881
<artifactId>modelmapper</artifactId>
99-
<version>2.3.0</version>
82+
<version>3.2.0</version>
10083
</dependency>
10184
<dependency>
10285
<groupId>org.springframework.boot</groupId>
@@ -110,26 +93,11 @@
11093
<groupId>org.springframework.cloud</groupId>
11194
<artifactId>spring-cloud-starter-openfeign</artifactId>
11295
</dependency>
113-
<dependency>
114-
<groupId>javax.validation</groupId>
115-
<artifactId>validation-api</artifactId>
116-
<version>2.0.1.Final</version>
117-
<scope>compile</scope>
118-
</dependency>
96+
11997

12098
</dependencies>
12199

122-
<dependencyManagement>
123-
<dependencies>
124-
<dependency>
125-
<groupId>org.springframework.cloud</groupId>
126-
<artifactId>spring-cloud-dependencies</artifactId>
127-
<version>${spring-cloud.version}</version>
128-
<type>pom</type>
129-
<scope>import</scope>
130-
</dependency>
131-
</dependencies>
132-
</dependencyManagement>
100+
133101

134102
<build>
135103
<plugins>

order-service/src/main/java/com/hoangtien2k3/orderservice/config/client/ClientConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public RestTemplate restTemplateBean() {
1414
return new RestTemplate();
1515
}
1616

17+
@LoadBalanced
1718
@Bean
1819
public WebClient.Builder webClientBuilder() {
1920
return WebClient.builder();

0 commit comments

Comments
 (0)