File tree Expand file tree Collapse file tree 6 files changed +52
-31
lines changed Expand file tree Collapse file tree 6 files changed +52
-31
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ Sample project to test and deploy spring boot application with mysql database in
66
77- Docker with kubernetes enabled
88- Kubernetes command-line tool(kubectl)
9- - Java
9+ - JDK 17 LTS
1010- Maven
1111
1212## Start application
Original file line number Diff line number Diff line change @@ -5,10 +5,10 @@ metadata:
55 labels :
66 app : mysql
77spec :
8- # type: NodePort
8+ # type: NodePort
99 ports :
1010 - port : 3306
11- # nodePort: 31000
11+ # nodePort: 31000
1212 selector :
1313 app : mysql
1414---
Original file line number Diff line number Diff line change 66
77 <groupId >com.ashu</groupId >
88 <artifactId >spring-boot-kubernetes-mysql</artifactId >
9- <version >4.0 .0</version >
9+ <version >4.1 .0</version >
1010 <packaging >jar</packaging >
1111
1212 <name >Spring-Boot-Kubernetes-MySQL</name >
1515 <parent >
1616 <groupId >org.springframework.boot</groupId >
1717 <artifactId >spring-boot-starter-parent</artifactId >
18- <version >2.4 .3</version >
18+ <version >2.6 .3</version >
1919 <relativePath /> <!-- lookup parent from repository -->
2020 </parent >
2121
2222 <properties >
23- <java .version>11 </java .version>
24- <jkube .version>1.1.1 </jkube .version>
23+ <java .version>17 </java .version>
24+ <jkube .version>1.6.0 </jkube .version>
2525 </properties >
2626
2727 <dependencies >
Original file line number Diff line number Diff line change 11package com .ashu .demo .model ;
22
3- import java .io .Serializable ;
4- import java .util .Date ;
3+ import lombok .Getter ;
4+ import lombok .NoArgsConstructor ;
5+ import lombok .Setter ;
56
67import javax .persistence .Entity ;
78import javax .persistence .Id ;
89import javax .persistence .Temporal ;
910import javax .persistence .TemporalType ;
10-
11- import lombok . Data ;
12- import lombok . NoArgsConstructor ;
11+ import java . io . Serial ;
12+ import java . io . Serializable ;
13+ import java . util . Date ;
1314
1415@ Entity
15- @ Data
16+ @ Setter
17+ @ Getter
1618@ NoArgsConstructor
1719public class Pet implements Serializable {
1820
19- private static final long serialVersionUID = 4889087778273529265L ;
21+ @ Serial
22+ private static final long serialVersionUID = 4889087778273529265L ;
23+
24+ @ Id
25+ private String name ;
2026
21- @ Id
22- private String name ;
27+ private String owner ;
2328
24- private String owner ;
29+ private String species ;
2530
26- private String species ;
31+ private char sex ;
2732
28- private char sex ;
33+ @ Temporal (TemporalType .DATE )
34+ private Date birth ;
2935
30- @ Temporal (TemporalType .DATE )
31- private Date birth ;
36+ @ Temporal (TemporalType .DATE )
37+ private Date death ;
3238
33- @ Temporal (TemporalType .DATE )
34- private Date death ;
39+ @ Override
40+ public String toString () {
41+ return "Pet{" +
42+ "name='" + name + '\'' +
43+ ", owner='" + owner + '\'' +
44+ ", species='" + species + '\'' +
45+ ", sex=" + sex +
46+ ", birth=" + birth +
47+ ", death=" + death +
48+ '}' ;
49+ }
3550}
Original file line number Diff line number Diff line change 1313@ RequiredArgsConstructor
1414@ Slf4j
1515@ RestController
16- @ RequestMapping (value = "/pets" , consumes = MediaType .APPLICATION_JSON_VALUE , produces = MediaType .APPLICATION_JSON_VALUE )
16+ @ RequestMapping (value = "/pets" ,
17+ consumes = MediaType .APPLICATION_JSON_VALUE ,
18+ produces = MediaType .APPLICATION_JSON_VALUE )
1719public class PetController {
1820
1921 private final PetRepository petRepository ;
@@ -27,7 +29,9 @@ public void create(@RequestBody Pet pet) {
2729 @ GetMapping
2830 public List <Pet > view () {
2931 log .info ("View method called" );
30- return petRepository .findAll ();
32+ List <Pet > pets = petRepository .findAll ();
33+ log .info ("Pet list :{}" , pets );
34+ return pets ;
3135 }
3236
3337}
Original file line number Diff line number Diff line change 1- server :
2- servlet :
3- context-path : /api/v1
4- # spring: # datasource:
5- # url: jdbc:mysql://localhost:3306/test # username: test_user
6- # password: test_user_pwd
1+ server :
2+ servlet :
3+ context-path : /api/v1
4+ # spring:
5+ # datasource:
6+ # url: jdbc:mysql://localhost:31000/petdb
7+ # username: root
8+ # password: password
You can’t perform that action at this time.
0 commit comments