[英]In Spring Web, how do I get the full URL of a @RestController?
可以說我將ApplicationContext
注入到bean中。 然后,我可以發現所有用RestController
注釋的bean。 我將如何發現與所述bean相關聯的基本URL?
例:
@Component
public class ServiceEnumerator {
@Autowired
private ApplicationContext context;
@PostConstruct
private void postConstruct() {
final Map<String, Object> beansToExpose = context.getBeansWithAnnotation(RestController.class);
}
}
按照標准,基本URL(上下文根)需要在配置文件中設置。 不確定以下內容是否對您有幫助。...嘗試在控制器中注入HttpServletRequest,然后從控制器中將其傳遞到所需的服務
@Context
private HttpServletRequest httpRequest;
LOGGER.info("URL "+httpRequest.getRequestURI());
如果您的網址是http:// localhost:8080 / services / v1 / hello,則將提供/ services / v1 / hello
這可以通過從bean工廠檢索bean定義並解析其元數據來實現。 例如:
metadata.getAnnotationAttributes( "org.springframework.web.bind.annotation.RestController")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.