Una forma sencilla de generar el URL base acorde con el contexto de ambiente de la aplicacion a partir del objeto request:
protected static String getBaseEnvLinkURL() { String baseEnvLinkURL=null; HttpServletRequest currentRequest = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); baseEnvLinkURL = "http://" + currentRequest.getLocalName(); // lazy about determining protocol if(currentRequest.getLocalPort() != 80) { baseEnvLinkURL += ":" + currentRequest.getLocalPort(); } if(!StringUtils.isEmpty(currentRequest.getContextPath())) { baseEnvLinkURL += currentRequest.getContextPath(); } return baseEnvLinkURL; }