SpringBoot entry notes (1)

This article is a SprintBoot learning introductory notes

1. Open Eclipse, the version is Oxygen 4.7.0

2. New project
NewProject->MavenProject->Next->Next

GroupId fills in com.learn, Artifactid fills in spring-boot-hello, complete

3. Configure pom.xml

Double-click pom.xml to open the pom.xml tab, because Test is not needed for the time being, delete Test related, and delete the project Test directory.
The modified pom.xml content is as follows

<project xmlns="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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.kfit</groupId>
  <artifactId>spring-boot-hello</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>spring-boot-hello</name>
  <url>http://maven.apache.org</url>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
</parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- 指定jdk1.8 -->
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
</project>

4. Create a new Controller class

The content is as follows

package com.learn.spring_boot_hello;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public  class Hello Controller {

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
}

5. Start in App.Java

package com.learn.spring_boot_hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Use @SpringBootApplication here to specify that this is a sprint boot application
 *
 */
@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
}

6. Right-click the project to Run, select App, Ok

7. Check the Console, if the output is as follows, it means that the operation is normal

8. Browser test
http://127.0.0.1:8080/hello
output
hello

(complete)

 

 



Guess you like

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