File tree Expand file tree Collapse file tree 6 files changed +132
-1
lines changed
java/com/chachae/actuator
test/java/com/chachae/actuator/controller Expand file tree Collapse file tree 6 files changed +132
-1
lines changed Original file line number Diff line number Diff line change 20
20
<module >java-api</module >
21
21
<module >spring-boot-jpa</module >
22
22
<module >spring-boot-async</module >
23
- <module >springb-boot-redis</module >
23
+ <module >spring-boot-redis</module >
24
+ <module >spring-boot-actuator</module >
24
25
</modules >
25
26
26
27
<!-- 依赖版本管理 -->
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
+ <parent >
6
+ <artifactId >JavaStudy</artifactId >
7
+ <groupId >com.chachae</groupId >
8
+ <version >1.0-SNAPSHOT</version >
9
+ </parent >
10
+ <modelVersion >4.0.0</modelVersion >
11
+
12
+ <artifactId >spring-boot-actuator</artifactId >
13
+
14
+ <dependencies >
15
+
16
+ <dependency >
17
+ <groupId >org.springframework.boot</groupId >
18
+ <artifactId >spring-boot-starter-actuator</artifactId >
19
+ </dependency >
20
+
21
+ <dependency >
22
+ <groupId >org.springframework.boot</groupId >
23
+ <artifactId >spring-boot-starter-security</artifactId >
24
+ </dependency >
25
+
26
+ <dependency >
27
+ <groupId >org.springframework.security</groupId >
28
+ <artifactId >spring-security-test</artifactId >
29
+ <scope >test</scope >
30
+ </dependency >
31
+
32
+ </dependencies >
33
+
34
+ </project >
Original file line number Diff line number Diff line change
1
+ package com .chachae .actuator ;
2
+
3
+ import org .springframework .boot .SpringApplication ;
4
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
+
6
+ /**
7
+ * @author chachae
8
+ * @since 2020/1/8 12:14
9
+ */
10
+ @ SpringBootApplication
11
+ public class ActuatorApplication {
12
+
13
+ public static void main (String [] args ) {
14
+
15
+ SpringApplication .run (ActuatorApplication .class );
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package com .chachae .actuator .controller ;
2
+
3
+ import org .springframework .web .bind .annotation .GetMapping ;
4
+ import org .springframework .web .bind .annotation .PathVariable ;
5
+ import org .springframework .web .bind .annotation .RequestMapping ;
6
+ import org .springframework .web .bind .annotation .RestController ;
7
+
8
+ /**
9
+ * @author chachae
10
+ * @since 2020/1/8 15:48
11
+ */
12
+ @ RestController
13
+ @ RequestMapping ("/index" )
14
+ public class IndexController {
15
+
16
+ @ GetMapping ("/get/{arg}" )
17
+ public String get (@ PathVariable Long arg ) {
18
+ return String .valueOf (arg );
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ server :
2
+ port : 8080
3
+ servlet :
4
+ context-path : /demo
5
+ # 若要访问端点信息,需要配置用户名和密码
6
+ spring :
7
+ security :
8
+ user :
9
+ name : admin
10
+ password : 123456
11
+ management :
12
+ # 端点信息接口使用的端口,为了和主系统接口使用的端口进行分离
13
+ server :
14
+ port : 8090
15
+ servlet :
16
+ context-path : /sys
17
+ # 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况
18
+ endpoint :
19
+ health :
20
+ show-details : always
21
+ # 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
22
+ endpoints :
23
+ web :
24
+ exposure :
25
+ include : ' *'
Original file line number Diff line number Diff line change
1
+ package com .chachae .actuator .controller ;
2
+
3
+ import org .junit .jupiter .api .BeforeEach ;
4
+ import org .junit .jupiter .api .Test ;
5
+ import org .springframework .boot .test .context .SpringBootTest ;
6
+ import org .springframework .http .MediaType ;
7
+ import org .springframework .test .web .servlet .MockMvc ;
8
+ import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
9
+ import org .springframework .test .web .servlet .result .MockMvcResultHandlers ;
10
+ import org .springframework .test .web .servlet .result .MockMvcResultMatchers ;
11
+ import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
12
+
13
+ /**
14
+ * @author chachae
15
+ * @since 2020/1/8 15:58
16
+ */
17
+ @ SpringBootTest
18
+ public class IndexControllerTests {
19
+
20
+ private MockMvc mvc ;
21
+
22
+ @ BeforeEach
23
+ public void setUp () {
24
+ mvc = MockMvcBuilders .standaloneSetup (new IndexController ()).build ();
25
+ }
26
+
27
+ @ Test
28
+ public void getArg () throws Exception {
29
+ mvc .perform (MockMvcRequestBuilders .get ("/index/get/1" ).accept (MediaType .APPLICATION_JSON ))
30
+ .andExpect (MockMvcResultMatchers .status ().isOk ())
31
+ .andDo (MockMvcResultHandlers .print ())
32
+ .andReturn ();
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments