Home - grandhappy/springboot GitHub Wiki
a journey to study springboot
quickstart
create maven project
how to create a simple springboot project?
- using maven project using maven-archetype-quickstart
- import parent project in pom file
- create main-function annotationed with @SpringBootApplication
- import spring-boot-maven-plugin plugin in pom file
project structrue
- src/main/java is srource folder
- test/main/java is test folder
- pom.xml is maven configration
create maven project
how to create a simple springboot project?
- using maven project using maven-archetype-quickstart
- import parent project in pom file
- create main-function annotationed with @SpringBootApplication
- import spring-boot-maven-plugin plugin in pom file
project structrue
- src/main/java is srource folder
- test/main/java is test folder
- pom.xml is maven configration
web project
How to design restfull interface?
- import spring-boot-starter-web dependence in pom file
- create controller annotationed with @RestController
- coding restfull interface annotationed with @RequestMapping
- mvn package
- run project using commond 'java -jar springboot-1.0-SNAP SHOT.jar'
- curl 'http://127.0.0.1:8080/index'
junit test
Mock with MockMvc to initiate the http request, which is actually a class method call, then execute the controller, using Mockito's mock to mock the return of the underlying data during the execution, and finally validate the result.
How to junit test?
- import spring-boot-starter-test dependence in pom file
- create test class in src/test folder annotationed with @RunWith @SpringBootTest @AutoConfigureMockMvc
- coding test function
junit interpretation
- @RunWith is used for running test
- @SpringBootTest is used for statementing springboot test
- @AutoConfigureMockMvc is used for autowiring beans