How to get spring boot controller endpoint full url? -
how specific spring boot controller endpoint full url without concat/hardcode strings? case need send request external url , async notification it, need pass notification endpoint full url it. here sample code:
@restcontroller @requestmapping("/api/v1") public class mycontroller { @postmapping("/sendrequest") public void sendrequest() { ... // 1. /notifystatus endpoint full url send external service string mynotificationfullurl = xxx ? // 2. call external service } @getmapping("/notifystatus") public void notifystatus() { ... } }
allows getting url on system, not current one.
import org.springframework.hateoas.mvc.controllerlinkbuilder ... controllerlinkbuilder linkbuilder = controllerlinkbuilder.linkto(methodon(yourcontroller.class).getsomeentitymethod(parameterid, parametertwoid)) uri methoduri = linkbuilder.uri() string methodurl = methoduri.getpath()
there more methods change host name, etc.
Comments
Post a Comment