Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
a8f1cfdd
Commit
a8f1cfdd
authored
Jul 09, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整合Actuator和Swagger
parent
617dc18c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
7 deletions
+55
-7
discovery-console/pom.xml
+5
-0
discovery-console/src/main/java/com/nepxion/discovery/console/configuration/ConsoleAutoConfiguration.java
+15
-2
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+30
-4
discovery-springcloud-example-console/src/main/resources/application.properties
+5
-1
No files found.
discovery-console/pom.xml
View file @
a8f1cfdd
...
...
@@ -31,6 +31,11 @@
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/configuration/ConsoleAutoConfiguration.java
View file @
a8f1cfdd
...
...
@@ -9,12 +9,16 @@ package com.nepxion.discovery.console.configuration;
* @version 1.0
*/
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
com.nepxion.discovery.console.endpoint.ConsoleEndpoint
;
@Configuration
@ComponentScan
(
basePackages
=
{
"com.nepxion.discovery.console.controller
"
})
// @ComponentScan(basePackages = { "com.nepxion.discovery.console.endpoint
" })
@Import
(
SwaggerConfiguration
.
class
)
public
class
ConsoleAutoConfiguration
{
static
{
...
...
@@ -30,4 +34,12 @@ public class ConsoleAutoConfiguration {
System
.
out
.
println
(
"Nepxion Discovery - Console v3.3.11"
);
System
.
out
.
println
(
""
);
}
@ConditionalOnClass
(
Endpoint
.
class
)
protected
static
class
ConsoleEndpointConfiguration
{
@Bean
public
ConsoleEndpoint
consoleEndpoint
()
{
return
new
ConsoleEndpoint
();
}
}
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/
controller/ConsoleController
.java
→
discovery-console/src/main/java/com/nepxion/discovery/console/
endpoint/ConsoleEndpoint
.java
View file @
a8f1cfdd
package
com
.
nepxion
.
discovery
.
console
.
controller
;
package
com
.
nepxion
.
discovery
.
console
.
endpoint
;
/**
* <p>Title: Nepxion Discovery</p>
...
...
@@ -16,27 +16,37 @@ import io.swagger.annotations.ApiParam;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.jmx.export.annotation.ManagedOperation
;
import
org.springframework.jmx.export.annotation.ManagedResource
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@Api
(
tags
=
{
"控制台接口"
})
public
class
ConsoleController
{
@ManagedResource
(
description
=
"Console Endpoint"
)
public
class
ConsoleEndpoint
implements
MvcEndpoint
{
@Autowired
private
DiscoveryClient
discoveryClient
;
@RequestMapping
(
path
=
"/services"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/
console/
services"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取服务注册中心所有服务列表"
,
notes
=
""
,
response
=
List
.
class
,
httpMethod
=
"GET"
)
@ResponseBody
@ManagedOperation
public
List
<
String
>
services
()
{
return
getServices
();
}
@RequestMapping
(
path
=
"/instances/{serviceId}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/
console/
instances/{serviceId}"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取服务注册中心服务的实例列表"
,
notes
=
""
,
response
=
List
.
class
,
httpMethod
=
"GET"
)
@ResponseBody
@ManagedOperation
public
List
<
ServiceInstance
>
instances
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
return
getInstanceList
(
serviceId
);
}
...
...
@@ -48,4 +58,19 @@ public class ConsoleController {
public
List
<
ServiceInstance
>
getInstanceList
(
String
serviceId
)
{
return
discoveryClient
.
getInstances
(
serviceId
);
}
@Override
public
String
getPath
()
{
return
"/"
;
}
@Override
public
boolean
isSensitive
()
{
return
true
;
}
@Override
public
Class
<?
extends
Endpoint
<?>>
getEndpointType
()
{
return
null
;
}
}
\ No newline at end of file
discovery-springcloud-example-console/src/main/resources/application.properties
View file @
a8f1cfdd
...
...
@@ -20,8 +20,12 @@ spring.cloud.zookeeper.discovery.preferIpAddress=true
ribbon.ReadTimeout
=
60000
ribbon.ConnectTimeout
=
60000
# Admin config
management.port
=
3333
management.security.enabled
=
false
# Swagger config
swagger.service.base.package
=
com.nepxion.discovery.console.
controller
swagger.service.base.package
=
com.nepxion.discovery.console.
endpoint
swagger.service.description
=
Console Restful APIs
swagger.service.version
=
1.0.0
swagger.service.license
=
Apache License 2.0
...
...
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