懒羊羊
2024-01-31 e57a8990ae56f657a59c435a0613c5f7a8728003
提交 | 用户 | 时间
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 }