Skip to content

Commit e5a3611

Browse files
committed
cleanups.. using swagger
1 parent bdc7059 commit e5a3611

File tree

17 files changed

+279
-80
lines changed

17 files changed

+279
-80
lines changed

admin-server-dashboard/pom.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
<version>1.0</version>
1010

1111
<properties>
12-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1412
<java.version>11</java.version>
1513
<spring-cloud.version>2021.0.7</spring-cloud.version>
1614
<spring-boot.version>2.7.11</spring-boot.version>
1715
<spring-boot-admin.version>2.7.10</spring-boot-admin.version>
1816

19-
<maven.compiler.source>11</maven.compiler.source>
20-
<maven.compiler.target>11</maven.compiler.target>
17+
<maven.compiler.source>${java.version}</maven.compiler.source>
18+
<maven.compiler.target>${java.version}</maven.compiler.target>
2119
</properties>
2220

2321
<dependencies>
@@ -44,7 +42,11 @@
4442
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
4543
<scope>runtime</scope>
4644
</dependency>
47-
45+
<dependency>
46+
<groupId>org.projectlombok</groupId>
47+
<artifactId>lombok</artifactId>
48+
<optional>true</optional>
49+
</dependency>
4850
</dependencies>
4951

5052

@@ -73,6 +75,14 @@
7375
<plugin>
7476
<groupId>org.springframework.boot</groupId>
7577
<artifactId>spring-boot-maven-plugin</artifactId>
78+
<configuration>
79+
<excludes>
80+
<exclude>
81+
<groupId>org.projectlombok</groupId>
82+
<artifactId>lombok</artifactId>
83+
</exclude>
84+
</excludes>
85+
</configuration>
7686
</plugin>
7787
</plugins>
7888
</build>
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
package gt.regdist;
22

33
import de.codecentric.boot.admin.server.config.EnableAdminServer;
4+
import lombok.extern.slf4j.Slf4j;
45
import org.springframework.boot.SpringApplication;
56
import org.springframework.boot.autoconfigure.SpringBootApplication;
67
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8+
import org.springframework.core.env.Environment;
9+
10+
import java.net.InetAddress;
11+
import java.net.UnknownHostException;
12+
import java.util.Arrays;
713

814
@EnableDiscoveryClient
915
@SpringBootApplication
1016
@EnableAdminServer
17+
@Slf4j
1118
public class DashboardApp {
1219

13-
public static void main(String[] args) {
14-
SpringApplication.run(DashboardApp.class, args);
15-
}
20+
public static void main(String[] args) throws UnknownHostException {
1621

22+
SpringApplication app = new SpringApplication(DashboardApp.class);
23+
Environment env = app.run(args).getEnvironment();
24+
25+
log.info("Access URLs:\n----------------------------------------------------------\n\t" +
26+
"Local: \t\t\thttp://localhost:{}\n\t" +
27+
"External: \t\thttp://{}:{}\n\t" +
28+
"Environment: \t{} \n" +
29+
"----------------------------------------------------------",
30+
env.getProperty("local.server.port"),
31+
InetAddress.getLocalHost().getHostAddress(),
32+
env.getProperty("local.server.port"),
33+
Arrays.toString(env.getActiveProfiles())
34+
);
35+
}
1736
}
1837

config-server/pom.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99
<version>1.0</version>
1010

1111
<properties>
12-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1412
<java.version>11</java.version>
1513
<spring-cloud.version>2021.0.7</spring-cloud.version>
1614
<spring-boot.version>2.7.11</spring-boot.version>
1715

18-
<maven.compiler.source>11</maven.compiler.source>
19-
<maven.compiler.target>11</maven.compiler.target>
16+
<maven.compiler.source>${java.version}</maven.compiler.source>
17+
<maven.compiler.target>${java.version}</maven.compiler.target>
2018
</properties>
2119

2220
<dependencies>
2321
<dependency>
2422
<groupId>org.springframework.cloud</groupId>
2523
<artifactId>spring-cloud-config-server</artifactId>
2624
</dependency>
27-
25+
<dependency>
26+
<groupId>org.projectlombok</groupId>
27+
<artifactId>lombok</artifactId>
28+
<optional>true</optional>
29+
</dependency>
2830
<dependency>
2931
<groupId>org.springframework.boot</groupId>
3032
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
@@ -57,6 +59,14 @@
5759
<plugin>
5860
<groupId>org.springframework.boot</groupId>
5961
<artifactId>spring-boot-maven-plugin</artifactId>
62+
<configuration>
63+
<excludes>
64+
<exclude>
65+
<groupId>org.projectlombok</groupId>
66+
<artifactId>lombok</artifactId>
67+
</exclude>
68+
</excludes>
69+
</configuration>
6070
</plugin>
6171
</plugins>
6272
</build>
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
package gt.config;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.cloud.config.server.EnableConfigServer;
7+
import org.springframework.core.env.Environment;
8+
9+
import java.net.InetAddress;
10+
import java.net.UnknownHostException;
11+
import java.util.Arrays;
612

713
@SpringBootApplication
814
@EnableConfigServer
15+
@Slf4j
916
public class ConfigApplication {
1017

11-
public static void main(String[] args) {
12-
SpringApplication.run(ConfigApplication.class, args);
18+
public static void main(String[] args) throws UnknownHostException {
19+
20+
SpringApplication app = new SpringApplication(ConfigApplication.class);
21+
Environment env = app.run(args).getEnvironment();
22+
23+
log.info("Access URLs:\n----------------------------------------------------------\n\t" +
24+
"Local: \t\t\thttp://localhost:{}\n\t" +
25+
"External: \t\thttp://{}:{}\n\t" +
26+
"Environment: \t{} \n" +
27+
"----------------------------------------------------------",
28+
env.getProperty("local.server.port"),
29+
InetAddress.getLocalHost().getHostAddress(),
30+
env.getProperty("local.server.port"),
31+
Arrays.toString(env.getActiveProfiles())
32+
);
1333
}
1434

1535
}

gateway-app/pom.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
<version>1.0</version>
1010

1111
<properties>
12-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1412
<java.version>11</java.version>
1513
<spring-cloud.version>2021.0.7</spring-cloud.version>
1614
<spring-boot.version>2.7.11</spring-boot.version>
1715

18-
<maven.compiler.source>11</maven.compiler.source>
19-
<maven.compiler.target>11</maven.compiler.target>
16+
<maven.compiler.source>${java.version}</maven.compiler.source>
17+
<maven.compiler.target>${java.version}</maven.compiler.target>
2018
</properties>
2119

2220

@@ -35,14 +33,13 @@
3533
</dependency>
3634
<dependency>
3735
<groupId>org.springframework.cloud</groupId>
38-
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
36+
<artifactId>spring-cloud-starter-openfeign</artifactId>
3937
</dependency>
40-
4138
<dependency>
42-
<groupId>org.springframework.cloud</groupId>
43-
<artifactId>spring-cloud-starter-openfeign</artifactId>
39+
<groupId>org.projectlombok</groupId>
40+
<artifactId>lombok</artifactId>
41+
<optional>true</optional>
4442
</dependency>
45-
4643
<dependency>
4744
<groupId>org.springframework.cloud</groupId>
4845
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
@@ -81,6 +78,14 @@
8178
<plugin>
8279
<groupId>org.springframework.boot</groupId>
8380
<artifactId>spring-boot-maven-plugin</artifactId>
81+
<configuration>
82+
<excludes>
83+
<exclude>
84+
<groupId>org.projectlombok</groupId>
85+
<artifactId>lombok</artifactId>
86+
</exclude>
87+
</excludes>
88+
</configuration>
8489
</plugin>
8590
</plugins>
8691
</build>
Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,62 @@
11
package gt.gatewayapp;
22

33
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
4-
import io.github.resilience4j.retry.annotation.Retry;
5-
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.slf4j.Slf4j;
76
import org.springframework.boot.SpringApplication;
87
import org.springframework.boot.autoconfigure.SpringBootApplication;
98
import org.springframework.boot.web.client.RestTemplateBuilder;
109
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
1110
import org.springframework.cloud.openfeign.EnableFeignClients;
1211
import org.springframework.cloud.openfeign.FeignClient;
1312
import org.springframework.context.annotation.Bean;
13+
import org.springframework.core.env.Environment;
1414
import org.springframework.stereotype.Component;
1515
import org.springframework.stereotype.Service;
1616
import org.springframework.web.bind.annotation.GetMapping;
1717
import org.springframework.web.bind.annotation.RequestMapping;
1818
import org.springframework.web.bind.annotation.RestController;
1919
import org.springframework.web.client.RestTemplate;
2020

21+
import java.net.InetAddress;
22+
import java.net.UnknownHostException;
2123
import java.time.LocalDateTime;
24+
import java.util.Arrays;
2225
import java.util.Map;
2326

2427
@SpringBootApplication
2528
@EnableFeignClients
29+
@Slf4j
2630
public class TestGatewayApplication {
2731

28-
public static void main(String[] args) {
29-
SpringApplication.run(TestGatewayApplication.class, args);
32+
public static void main(String[] args) throws UnknownHostException {
33+
34+
SpringApplication app = new SpringApplication(TestGatewayApplication.class);
35+
Environment env = app.run(args).getEnvironment();
36+
37+
log.info("Access URLs:\n----------------------------------------------------------\n\t" +
38+
"Local: \t\t\thttp://localhost:{}\n\t" +
39+
"External: \t\thttp://{}:{}\n\t" +
40+
"Environment: \t{} \n" +
41+
"----------------------------------------------------------",
42+
env.getProperty("local.server.port"),
43+
InetAddress.getLocalHost().getHostAddress(),
44+
env.getProperty("local.server.port"),
45+
Arrays.toString(env.getActiveProfiles())
46+
);
3047
}
31-
3248
@Bean
33-
@LoadBalanced
34-
//this will search in the registry
49+
@LoadBalanced //this will search in the registry
3550
RestTemplate restTemplate(RestTemplateBuilder rtb) {
3651
return rtb.build();
3752
}
3853

3954
@RestController
55+
@RequiredArgsConstructor
4056
static class GatewayAppController {
4157
private final GreetingService greetingService;
4258
private final TimeService timeService;
4359

44-
GatewayAppController(GreetingService greetingService, TimeService timeService) {
45-
this.greetingService = greetingService;
46-
this.timeService = timeService;
47-
}
48-
4960
@RequestMapping({"/", ""})
5061
public String home() {
5162
Map<String, String> resp = timeService.getTime();
@@ -61,13 +72,10 @@ public String home() {
6172
}
6273

6374
@Service
75+
@Slf4j
76+
@RequiredArgsConstructor
6477
class GreetingService {
6578
private final RestTemplate restTemplate;
66-
private final Logger log = LoggerFactory.getLogger(GreetingService.class);
67-
68-
GreetingService(RestTemplate restTemplate) {
69-
this.restTemplate = restTemplate;
70-
}
7179

7280
@CircuitBreaker(name = "getGreeting", fallbackMethod = "getDefaultGreeting")
7381
String getGreeting() {
@@ -81,20 +89,19 @@ public String getDefaultGreeting(Throwable t) {
8189

8290
}
8391

84-
@FeignClient(value = "time-service", fallback = HystrixFallbackTimeService.class)
92+
@FeignClient(value = "time-service", fallback = FallbackTimeService.class)
8593
interface TimeService {
8694

8795
@GetMapping({"/api/time/"})
8896
Map<String, String> getTime();
8997

9098
}
9199

92-
@Component
93-
//it won't be the primary bean
94-
class HystrixFallbackTimeService implements TimeService {
100+
@Component //it won't be the primary bean
101+
class FallbackTimeService implements TimeService {
95102

96103
@Override
97104
public Map<String, String> getTime() {
98-
return Map.of("servertime", "Fallback to" + LocalDateTime.now().toString());
105+
return Map.of("servertime", "Fallback to" + LocalDateTime.now());
99106
}
100107
}

0 commit comments

Comments
 (0)