Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53d3873

Browse files
committed
Spring Boot package
1 parent3c8854c commit53d3873

File tree

19 files changed

+405
-1
lines changed

19 files changed

+405
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Spring Boot 使用的各种示例,以最简单、最实用为标准,此开
3737
-[spring-boot-scheduler](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-scheduler):Spring Boot 3.0 定时任务 scheduler 使用示例
3838
-[spring-boot-mail](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-mail):Spring Boot 3.0 邮件发送使用示例
3939
-[spring-boot-mongodb](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-mongodb):Spring Boot 3.0 MongoDB 增删改查示例 多数据源使用案例
40-
40+
-[spring-boot-package](https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-package):Spring Boot 3.0 单元测试、集成测试、打 Jar/War 包、定制启动参数使用案例
4141

4242

4343

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.neo</groupId>
7+
<artifactId>spring-boot-package-war</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>war</packaging>
10+
11+
<name>spring-boot-package-war</name>
12+
<description>Demo project for Spring Boot package war</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>3.0.0</version>
18+
<relativePath/><!-- lookup parent from repository-->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>17</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.junit.vintage</groupId>
37+
<artifactId>junit-vintage-engine</artifactId>
38+
<scope>test</scope>
39+
<exclusions>
40+
<exclusion>
41+
<groupId>org.hamcrest</groupId>
42+
<artifactId>hamcrest-core</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-web</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-tomcat</artifactId>
53+
<scope>provided</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-devtools</artifactId>
58+
<optional>true</optional>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-maven-plugin</artifactId>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
72+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
packagecom.neo;
2+
3+
importorg.springframework.boot.SpringApplication;
4+
importorg.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
publicclassApplication {
8+
9+
publicstaticvoidmain(String[]args) {
10+
SpringApplication.run(Application.class,args);
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packagecom.neo;
2+
3+
importorg.springframework.boot.builder.SpringApplicationBuilder;
4+
importorg.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5+
6+
/**
7+
* Created by summer on 2017/5/8.
8+
*/
9+
publicclassServletInitializerextendsSpringBootServletInitializer {
10+
@Override
11+
protectedSpringApplicationBuilderconfigure(SpringApplicationBuilderapplication) {
12+
returnapplication.sources(Application.class);
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.neo.controller;
2+
3+
importorg.springframework.web.bind.annotation.RequestMapping;
4+
importorg.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
publicclassHelloWorldController {
8+
9+
@RequestMapping("/hello")
10+
publicStringindex() {
11+
return"Hello World";
12+
}
13+
}

‎spring-boot-package/spring-boot-package-war/src/main/resources/application.properties‎

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packagecom.neo;
2+
3+
importorg.junit.Test;
4+
importorg.junit.runner.RunWith;
5+
importorg.springframework.test.context.junit4.SpringJUnit4ClassRunner;
6+
7+
@RunWith(SpringJUnit4ClassRunner.class)
8+
publicclassApplicationTests {
9+
10+
@Test
11+
publicvoidcontextLoads() {
12+
}
13+
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
packagecom.neo.controller;
2+
3+
importorg.junit.Before;
4+
importorg.junit.Test;
5+
importorg.junit.runner.RunWith;
6+
importorg.springframework.http.MediaType;
7+
importorg.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8+
importorg.springframework.test.context.web.WebAppConfiguration;
9+
importorg.springframework.test.web.servlet.MockMvc;
10+
importorg.springframework.test.web.servlet.request.MockMvcRequestBuilders;
11+
importorg.springframework.test.web.servlet.setup.MockMvcBuilders;
12+
13+
importstaticorg.hamcrest.Matchers.equalTo;
14+
importstaticorg.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
15+
importstaticorg.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16+
17+
@RunWith(SpringJUnit4ClassRunner.class)
18+
@WebAppConfiguration
19+
publicclassHelloTests {
20+
21+
22+
privateMockMvcmvc;
23+
24+
@Before
25+
publicvoidsetUp()throwsException {
26+
mvc =MockMvcBuilders.standaloneSetup(newHelloWorldController()).build();
27+
}
28+
29+
@Test
30+
publicvoidgetHello()throwsException {
31+
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
32+
.andExpect(status().isOk())
33+
.andExpect(content().string(equalTo("Hello World")));
34+
}
35+
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
packagecom.neo.controller;
2+
3+
importorg.junit.Before;
4+
importorg.junit.Test;
5+
importorg.junit.runner.RunWith;
6+
importorg.springframework.http.MediaType;
7+
importorg.springframework.mock.web.MockServletContext;
8+
importorg.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9+
importorg.springframework.test.context.web.WebAppConfiguration;
10+
importorg.springframework.test.web.servlet.MockMvc;
11+
importorg.springframework.test.web.servlet.request.MockMvcRequestBuilders;
12+
importorg.springframework.test.web.servlet.result.MockMvcResultHandlers;
13+
importorg.springframework.test.web.servlet.result.MockMvcResultMatchers;
14+
importorg.springframework.test.web.servlet.setup.MockMvcBuilders;
15+
16+
@RunWith(SpringJUnit4ClassRunner.class)
17+
@WebAppConfiguration
18+
publicclassHelloWorldControlerTests {
19+
20+
privateMockMvcmvc;
21+
22+
@Before
23+
publicvoidsetUp()throwsException {
24+
mvc =MockMvcBuilders.standaloneSetup(newHelloWorldController()).build();
25+
}
26+
27+
@Test
28+
publicvoidgetHello()throwsException {
29+
mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
30+
.andExpect(MockMvcResultMatchers.status().isOk())
31+
.andDo(MockMvcResultHandlers.print())
32+
.andReturn();
33+
}
34+
35+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.neo</groupId>
7+
<artifactId>spring-boot-package</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-package</name>
12+
<description>Demo project for Spring Boot package war</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>3.0.0</version>
18+
<relativePath/><!-- lookup parent from repository-->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>17</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.junit.vintage</groupId>
37+
<artifactId>junit-vintage-engine</artifactId>
38+
<scope>test</scope>
39+
<exclusions>
40+
<exclusion>
41+
<groupId>org.hamcrest</groupId>
42+
<artifactId>hamcrest-core</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
58+
</project>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp