Use Maven to build a spring boot2.0 project under MyEclipse

Source: Internet
Author: User

Now it's time to build the Spring boot framework and implement a HelloWorld project to get the program up and running.

First, introduced in the Pom.xml spring-boot-start-parent,spring official called stater Poms, it can provide dependency management, that is, rely on management, In the future, when declaring other dependency, no version is needed.

<Parent>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring-boot-starter-parent</Artifactid>    <version>2.0.0.RELEASE</version></Parent>

Second, the need to introduce spring-boot-starter-web,spring official explanation in Pom.xml Spring-boot-start-web contains features of web development such as spring WEBMVC and Tomcat.

<Dependencies>    <Dependency>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-web</Artifactid>    </Dependency></Dependencies>

Third, if we want to direct main to start spring, then the following plugin must be added, otherwise it will not start. This configuration is not required if you are using Maven's spring-boot:run.

<Plugins>    <plugin>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-maven-plugin</Artifactid>    </plugin></Plugins>

Four, start writing the program, we need a startup class, and then in the launch class declaration let spring boot automatically give us the configuration spring needs, such as: @SpringBootApplication, in order to get the program to run quickly, Let's simply write an example of a browser accessing the word Hello World:

 PackageHello;Importorg.springframework.boot.*;ImportOrg.springframework.boot.autoconfigure.*;ImportOrg.springframework.stereotype.*;Importorg.springframework.web.bind.annotation.*; @Controller @enableautoconfiguration Public classSamplecontroller {@RequestMapping ("Home") @ResponseBody String Home () {return"Hello world!"; }     Public Static voidMain (string[] args)throwsException {springapplication.run (samplecontroller.class, args); }}

Where @enableautoconfiguration declares that spring boot automatically makes the necessary configuration for the program, equivalent to using @configuration,@ with default properties Enableautoconfiguration and @componentscan.

@RestController return data from a JSON string, you can write a restful interface directly.

Five, running our application, especially simple: Right-click Run as--Java application. Then open the browser input address: Http://127.0.0.1:8080/home can see Hello world!.

Vi. Complete Pom.xml file

<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.zst</groupId>  <Artifactid>Mymaven</Artifactid>  <Packaging>War</Packaging>  <version>0.0.1-snapshot</version>  <name>Mymaven Maven Webapp</name>  <URL>http://maven.apache.org</URL>  <Parent>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring-boot-starter-parent</Artifactid>    <version>2.0.0.RELEASE</version>  </Parent>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>3.8.1</version>      <Scope>Test</Scope>    </Dependency>    <Dependency>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-web</Artifactid>    </Dependency>  </Dependencies>  <Build>    <Finalname>Mymaven</Finalname>  </Build></Project>

To some, our Spring boot project has been completed and the HelloWorld project has been successfully run.

Reference: http://blog.csdn.net/a78270528/article/details/77573818

Use Maven to build a spring boot2.0 project under MyEclipse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.