Using Maven to build the SpringBoot project in MyEclipse, mavenspringboot
Now we need to build a spring boot framework and implement a HelloWorld project to let the program really run.
1. Introduce spring-boot-start-parent in pom. xml. The official spring name is stater poms,
It can provide dependency management, that is, dependency management. After the introduction, it does not need version when declaring other dependency.
org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
2. spring-boot-starter-web needs to be introduced in pom. xml. spring officially explains that spring-boot-start-web includes web development features such as spring webmvc and tomcat.
org.springframework.boot
spring-boot-starter-web
3. If we want to directly start spring using Main, the following plug-in must be added; otherwise, it cannot be started. This configuration is not required if maven's spring-boot: run is used.
org.springframework.boot
spring-boot-maven-plugin
4. Write the program below. We need a startup class, and then let spring boot automatically configure the spring configurations in the startup class declaration, for example: @ SpringBootApplication, to make the program run as soon as possible, we will simply write an example of accessing the hello world via a browser:
package com.whf.chen;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** */@SpringBootApplication@RestControllerpublic class SpringBootHelloWorld { @RequestMapping("/chen") public String hello() { return "Hello Spring Boot!"; } public static void main(String[] args) { SpringApplication.run(SpringBootHelloWorld.class, args); }}
The @ SpringBootApplication Declaration allows spring boot to automatically configure the program. It is equivalent to using @ Configuration, @ EnableAutoConfiguration, and @ ComponentScan as the default attribute.
@ RestController: Return json string data. You can directly write a RESTFul interface.
5. Run our Application. First, we will introduce the first running method.
The first method is particularly simple: Right-click Run As-> Java Application. Then open the browser and enter the address https: // 127.0.0.1: 8080/chen to see Hello Spring Boot! .
In the second method, right-click project-Run as-Maven build-in Goals, enter spring-boot: run, Apply, and click Run.
6. Complete pom. xml file
4.0.0
com.whf.chen
springboot_helloworld
war
0.0.1-SNAPSHOT
springboot_helloworld Maven Webapp
https://maven.apache.org
org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
junit
junit
3.8.1
test
javax.servlet
javax.servlet-api
3.1.0
org.springframework.boot
spring-boot-starter-web
springboot_helloworld
To some extent, our Spring boot project has been built and the HelloWorld project has been successfully run.