Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
2f535082
Commit
2f535082
authored
Jan 17, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取完整的服务地址
parent
d872c66d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
21 deletions
+14
-21
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ServerConfig.java
+14
-21
No files found.
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ServerConfig.java
View file @
2f535082
package
com
.
ruoyi
.
framework
.
config
;
import
org.springframework.boot.web.context.WebServerInitializedEvent
;
import
org.springframework.context.ApplicationListener
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.stereotype.Component
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
com.ruoyi.framework.util.ServletUtils
;
/**
* 服务相关配置
...
...
@@ -13,28 +11,23 @@ import java.net.UnknownHostException;
*
*/
@Component
public
class
ServerConfig
implements
ApplicationListener
<
WebServerInitializedEvent
>
public
class
ServerConfig
{
private
int
serverPort
;
/**
* 获取完整的请求路径,包括:域名,端口,上下文访问路径
*
* @return 服务地址
*/
public
String
getUrl
()
{
InetAddress
address
=
null
;
try
{
address
=
InetAddress
.
getLocalHost
();
}
catch
(
UnknownHostException
e
)
{
e
.
printStackTrace
();
}
return
"http://"
+
address
.
getHostAddress
()
+
":"
+
this
.
serverPort
;
HttpServletRequest
request
=
ServletUtils
.
getRequest
();
return
getDomain
(
request
);
}
@Override
public
void
onApplicationEvent
(
WebServerInitializedEvent
event
)
public
static
String
getDomain
(
HttpServletRequest
request
)
{
this
.
serverPort
=
event
.
getWebServer
().
getPort
();
StringBuffer
url
=
request
.
getRequestURL
();
String
contextPath
=
request
.
getServletContext
().
getContextPath
();
return
url
.
delete
(
url
.
length
()
-
request
.
getRequestURI
().
length
(),
url
.
length
()).
append
(
contextPath
).
toString
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment