Write your first Springboot application

Source: Internet
Author: User

1.1.1. Setting the parent of spring boot
<parent>      <groupId>org.springframework.boot</groupId>      <artifactId> spring-boot-starter-parent</artifactid>      <version>1.5.2.RELEASE</version>   </parent >

Description: The spring boot project must have the parent set to spring Boot's parent, which contains a large number of default configurations, which greatly simplifies our development.

1.1.2. Importing Spring Boot Web support
<dependency>        <groupId>org.springframework.boot</groupId>        <artifactId> Spring-boot-starter-web</artifactid>      </dependency>

  

1.1.3. Adding a Spring Boot plugin
<plugin>           <groupId>org.springframework.boot</groupId>           <artifactId> Spring-boot-maven-plugin</artifactid>        </plugin>
1.1.4. Writing the first spring boot application
@Controller @springbootapplication@configurationpublic class Helloapplication {       @RequestMapping ("Hello")    @ Responsebody public    String Hello () {        return ' Hello world! ";    }       public static void Main (string[] args) {        springapplication.run (helloapplication.class, args);    

Code Description:

1, @SpringBootApplication: The core annotation of the Spring boot project, the main purpose is to turn on automatic configuration. ;

2. @Configuration: This is a configuration class that configures spring;

3, @Controller: Marked this is a SPRINGMVC controller controllers;

4, Main method: In the Main method to start an application, that is: the application of the portal;

1.1.5. Launching the app

In the spring boot project, there are two ways to start a direct run Java application and another is to run through the spring boot maven plugin.

The first type:

The second type:

Start effect:

See the following information to indicate that the boot was successful:

INFO 6188---[main] c.i.springboot.demo.helloapplication:started helloapplication in 3.281 seconds (JVM Running for 3.601)

1.1.6. Testing

Open the browser and enter the address:

Effect:

Isn't it easy?

Writing the first Springboot app

Related Article

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.