提交 | 用户 | 时间
|
e57a89
|
1 |
package com.jcdm.framework.config; |
懒 |
2 |
|
|
3 |
import javax.servlet.http.HttpServletRequest; |
|
4 |
import org.springframework.stereotype.Component; |
|
5 |
import com.jcdm.common.utils.ServletUtils; |
|
6 |
|
|
7 |
/** |
|
8 |
* 服务相关配置 |
|
9 |
* |
|
10 |
* @author jc |
|
11 |
*/ |
|
12 |
@Component |
|
13 |
public class ServerConfig |
|
14 |
{ |
|
15 |
/** |
|
16 |
* 获取完整的请求路径,包括:域名,端口,上下文访问路径 |
|
17 |
* |
|
18 |
* @return 服务地址 |
|
19 |
*/ |
|
20 |
public String getUrl() |
|
21 |
{ |
|
22 |
HttpServletRequest request = ServletUtils.getRequest(); |
|
23 |
return getDomain(request); |
|
24 |
} |
|
25 |
|
|
26 |
public static String getDomain(HttpServletRequest request) |
|
27 |
{ |
|
28 |
StringBuffer url = request.getRequestURL(); |
|
29 |
String contextPath = request.getServletContext().getContextPath(); |
|
30 |
return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(contextPath).toString(); |
|
31 |
} |
|
32 |
} |