I'm using Spring Boot to build a REST API. In my situation, there are 2 controllers: ExportController
and ImportController
. Please check the example code here:
Export Controller:
@RestController
public class ExportController {
@GetMapping(value = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<Resource> export(@RequestParam("id") String id) {
// Processing...
}
}
Import Controller:
@RestController
public class ImportController {
@PostMapping(value = "/import", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> importData(HttpServletRequest request) {
// Processing...
// What should I do here?
String url = ...
}
}
Inside my ImportController
, I want to generate a URL pointing to the /export
endpoint, e.g. http://www.example.com/export?id=1234
.
I don't configure anything about the host or port in the application.properties
. I want to get them at runtime.
Could you please show me how to achieve it? I searched a lot on the Internet but couldn't find the answer. Thank you for your help.