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 {
}
ext {
set('springBootAdminVersion', "2.2.3")
set('springCloudVersion', "Hoxton.SR4")
}
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-web'
implementation 'de.codecentric:spring-boot-admin-starter-client'
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'
annotationProcessor 'org.projectlombok:lombok'
compile "io.springfox:springfox-swagger2: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') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
}
dependencyManagement {
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;
import com.nisum.ecomcustomer.model.CustomerType;
import com.nisum.ecomcustomer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -13,11 +14,12 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.LocalDate;
import java.util.List;
@RefreshScope
@RestController
@RequestMapping("/customer")
@Validated
public class CustomerController {
......@@ -45,7 +47,8 @@ public class CustomerController {
}
@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));
}
......@@ -82,7 +85,8 @@ public class CustomerController {
}
@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);
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:
port: 8008
spring:
profiles:
active: development
data:
mongodb:
host: localhost
port: 27017
database: ecom
management:
endpoints:
web:
exposure:
include: '*'
spring:
application:
name: customer
\ No newline at end of file
name: ecom-customer
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