Spring-boot-helloworld Development (Part 1)

Introduction to springboot

Spring Boot is a new framework provided by the Pivotal team, designed to simplify the initial setup and development of new Spring applications. The framework uses a specific way to configure, so that developers no longer need to define boilerplate configuration. In this way, Boot aims to be a leader in the burgeoning field of rapid application development.

springboot features

Ø Create a standalone spring application

Ø Embed tomcat, no need to deploy war file

Ø Simplified maven configuration

Ø Provide build-ready functions such as embedded server, security, heartbeat check, external configuration, etc.

Ø Emergency use out of the box, no code generation, no need to configure xml files.

Development environment preparation

Ø Development environment jdk1.7 or 1.8

Ø Development tool Eeclipse4.2

Ø Project management tool apache-maven-3.3.9

Create a workspace

Use eclipse to create a new maven web project project named: spring-boot-hello




After successful creation, the directory structure is as follows:


 Introduce spring-boot jar package in pom.xml

<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.0http://maven.apache.org/maven-v4_0_0.xsd">

         <modelVersion>4.0.0</modelVersion>

         <groupId>cn.mybatis-demo</groupId>

         <artifactId>springboot-hello</artifactId>

         <packaging>war</packaging>

         <version>0.0.1-SNAPSHOT</version>

         <name>springboot-helloMaven Webapp</name>

         <url>http://maven.apache.org</url>

         <!-- Introduce the spring-boot parent node, no conditional version number is required, spring boot will automatically select the appropriate version to add the jar package -->

         <parent>

                   <groupId>org.springframework.boot</groupId>

                   <artifactId>spring-boot-starter-parent</artifactId>

                   <version>1.4.1.RELEASE</version>

         </parent>

         <dependencies>

                   <!-- Introduce spring-boot-web jar package -->

                   <dependency>

                            <groupId>org.springframework.boot</groupId>

                            <artifactId>spring-boot-starter-web</artifactId>

                   </dependency>

                   <!-- Introduce spring-boot-test test package -->

                   <dependency>

                            <groupId>org.springframework.boot</groupId>

                            <artifactId>spring-boot-starter-test</artifactId>

                   </dependency>

         </dependencies>

 

         <build>

                   <finalName>springboot</finalName>

                   <plugins>

                            <!-- Introduce spring tomcat plug-in package -->

                            <plugin>

                                     <groupId>org.springframework.boot</groupId>

                                     <artifactId>spring-boot-maven-plugin</artifactId>

                            </plugin>

                   </plugins>

         </build>

</project>


Write the HelloWorldController class

/**

 * Equivalent to @Controler @ResponseBody using @RestController

 * @author Administrator

 *

 */

@RestController

public class HelloWorldController {

   /**

    * Request mapping: http://localhost:8080/hello

    * @return

    */

   @RequestMapping("/hello")

   public String hello() {

      System.out.println("hello...........");

      return"hello";

   }

}

Write the spring-boot startup class

@SpringBootApplication

public class App {

   public static void main(String[] args) {

      SpringApplication.run(App.class, args);

   }

}

Select the startup class, right-click, select java application to run and start spring-boot. The default startup tomcat port is 8080

The startup result is as follows:



Test Results



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325589846&siteId=291194637