Created
November 24, 2022 07:00
-
-
Save wenqiglantz/30b654361ec69b566662f640322eddda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping(value = "/customers", produces = MediaType.APPLICATION_JSON_VALUE) | |
@ImportRuntimeHints(CustomerController.CustomerControllerRuntimeHints.class) | |
public class CustomerController { | |
private final CustomerService customerService; | |
public CustomerController(CustomerService customerService) { | |
this.customerService = customerService; | |
} | |
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) | |
public ResponseEntity createCustomer(@RequestBody CustomerVO customerVO, UriComponentsBuilder uriBuilder) | |
throws Exception { | |
CustomerVO newCustomerVO = customerService.saveCustomer(customerVO); | |
URI location = uriBuilder | |
.path("/customers/{customerId}") | |
.buildAndExpand(newCustomerVO.getCustomerId()) | |
.toUri(); | |
return ResponseEntity.created(location) | |
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)) | |
.body(CustomerVO.builder() | |
.customerId(newCustomerVO.getCustomerId()) | |
.firstName(newCustomerVO.getFirstName()) | |
.lastName(newCustomerVO.getLastName()) | |
.build()); | |
} | |
static class CustomerControllerRuntimeHints implements RuntimeHintsRegistrar { | |
@Override | |
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | |
hints.reflection() | |
.registerConstructor( | |
CustomerService.class.getConstructors()[0], ExecutableMode.INVOKE) | |
.registerMethod(ReflectionUtils.findMethod( | |
CustomerService.class, "saveCustomer", CustomerVO.class), ExecutableMode.INVOKE); | |
hints.resources().registerPattern("db/changelog/db.changelog-master.xml"); | |
hints.resources().registerPattern("db/changelog/db.changelog-1.0.xml"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment