The setup process is as follows:
First, the Environment preparation:
Install the JDK environment and search the Web tutorial yourself.
Download and install MAVEN.
Download and install the STS. Download URL: https://spring.io/tools/sts/all/
Second, build HelloWorld project
1. Select the Create Springboot Wizard
Path: file->new->spring Start Project
Select Web attributes, create a new Springboot project,
2. The following dependencies exist in the Pom.xml file.
<dependencies><dependency><groupid>org.springframework.boot</groupid><artifactid >spring-boot-starter-web</artifactId></dependency><dependency><groupId> Org.springframework.boot</groupid><artifactid>spring-boot-starter-test</artifactid><scope >test</scope></dependency></dependencies>
3. Create a Helloworldcontroller class
@RestControllerpublic class Helloworldcontroller {@RequestMapping ("/hello") public String Index () {return ' Hello World "; }}
4. Run the Helloworldapplication class to start the service
5. Browser Input Http://127.0.0.1:8080/hello
6. Interface Output HelloWorld
The project was built successfully.
Third, testing
Create a test class to print execution results
@RunWith (springjunit4classrunner.class) @WebAppConfigurationpublic class helloworldcontrolertests { private MockMvc mvc; @Before public void setup () throws Exception { mvc = mockmvcbuilders.standalonesetup (New helloworldcontroller ()). Build (); } @Test public void gethello () Throws exception { mvc.perform (Mockmvcrequestbuilders.get ("/hello"). Accept ( Mediatype.application_json)) .andexpect (Mockmvcresultmatchers.status (). IsOk ()) .anddo (Mockmvcresulthandlers.print ()) .andreturn (); }}
Result:
mockhttpservletrequest: http method = get request uri = /hello parameters = {} headers = {accept=[ Application/json]}handler: type = com.example.demo.HelloWorldController method = public java.lang.string com.example.demo.helloworldcontroller.index () Async: async started = false async result = nullResolved Exception: type = nullmodelandview: view name = null view = null Model = nullFlashMap: Attributes = nullMockHttpServletResponse: status = 200 error message = null headers = {content-type=[application/ json;charset=iso-8859-1], content-length=[15]} content type = application/json;charset=ISO-8859-1 Body = Hello World LJZ Forwarded URL = null redirected url = null cookies = []
This article is from the "technical footprint" blog, so be sure to keep this source http://liangjingzhi.blog.51cto.com/13234473/1967970
On spring boot (i) HelloWorld