Commit a1954127 authored by Ashok Kumar K's avatar Ashok Kumar K

added cloud config client and externalized config in git

parent 67bff2ac
...@@ -19,29 +19,30 @@ repositories { ...@@ -19,29 +19,30 @@ repositories {
} }
ext { ext {
set('springBootAdminVersion', "2.2.3") set('springCloudVersion', "Hoxton.SR4")
} }
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'de.codecentric:spring-boot-admin-starter-client'
compile 'org.springframework.boot:spring-boot-starter-validation' compile 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
compile "io.springfox:springfox-swagger2:2.9.2" compile "io.springfox:springfox-swagger2:2.9.2"
compile "io.springfox:springfox-swagger-ui:2.9.2" compile "io.springfox:springfox-swagger-ui:2.9.2"
developmentOnly 'org.springframework.boot:spring-boot-devtools' // developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
} }
testImplementation 'io.projectreactor:reactor-test'
} }
dependencyManagement { dependencyManagement {
imports { imports {
mavenBom "de.codecentric:spring-boot-admin-dependencies:${springBootAdminVersion}" mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
} }
} }
......
...@@ -4,6 +4,7 @@ import com.nisum.ecomcustomer.model.Customer; ...@@ -4,6 +4,7 @@ import com.nisum.ecomcustomer.model.Customer;
import com.nisum.ecomcustomer.model.CustomerType; import com.nisum.ecomcustomer.model.CustomerType;
import com.nisum.ecomcustomer.service.CustomerService; import com.nisum.ecomcustomer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -13,11 +14,12 @@ import org.springframework.web.bind.annotation.*; ...@@ -13,11 +14,12 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Email; import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
@RefreshScope
@RestController @RestController
@RequestMapping("/customer")
@Validated @Validated
public class CustomerController { public class CustomerController {
...@@ -45,7 +47,8 @@ public class CustomerController { ...@@ -45,7 +47,8 @@ public class CustomerController {
} }
@GetMapping("/id/{id}") @GetMapping("/id/{id}")
public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) { public ResponseEntity<Customer> getCustomerById(@PathVariable("id") @Pattern(regexp = "^[1-9][\\d]*$", message = "must be a numeric id") String idStr) {
long id = Long.parseLong(idStr);
return ResponseEntity.ok(customerService.getCustomerById(id)); return ResponseEntity.ok(customerService.getCustomerById(id));
} }
...@@ -82,7 +85,8 @@ public class CustomerController { ...@@ -82,7 +85,8 @@ public class CustomerController {
} }
@DeleteMapping("/id/{id}") @DeleteMapping("/id/{id}")
public ResponseEntity<Void> deleteById(@PathVariable Long id) { public ResponseEntity<Void> deleteById(@PathVariable("id") @Pattern(regexp = "^[1-9][\\d]*$", message = "must be a numeric id") String idStr) {
long id = Long.parseLong(idStr);
customerService.deleteById(id); customerService.deleteById(id);
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} }
......
package com.nisum.ecomcustomer.validators;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {NumericIdValidator.class})
@Documented
public @interface NumericId {
String message() default "must be a numeric id matching pattern [1-9][\\d]*";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
package com.nisum.ecomcustomer.validators;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
public class NumericIdValidator implements ConstraintValidator<NumericId, String> {
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return value.matches("[1-9][\\d]*");
}
}
spring:
data:
mongodb:
host: localhost
port: 27017
database: ecom
logging:
level:
web: debug
\ No newline at end of file
server:
port: 8181
spring:
data:
mongodb:
host: localhost
port: 27017
database: ecom-test
logging:
level:
web: debug
\ No newline at end of file
server: server:
port: 8008 port: 8008
spring:
profiles:
active: development
data:
mongodb:
host: localhost
port: 27017
database: ecom
management:
endpoints:
web:
exposure:
include: '*'
spring: spring:
application: application:
name: customer name: ecom-customer
\ No newline at end of file profiles:
active: development
cloud:
config:
uri: http://localhost:8888
#http://localhost:8888 is default we can change it if needed
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment