Using Maven to build the SpringBoot project in MyEclipse, mavenspringboot

Source: Internet
Author: User

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.

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.