SpringBoot helloworld

1. 构建工程

a. 地址:http://start.spring.io/

b. 填写Group、Artifact

c. 生成工程、下载、解压

2. 项目结构

3. 添加controller内容

新建文件:HelloController.java

package com.jihite.helloworld.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String index() {
        return "Hello World~";
    }
}

4. pom.xml

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>

5. 运行main函数

请求:http://localhost:8080/hello

返回:Hello World~

 

问题

1.提示接口被占用,如何更换默认端口8080

在springboot资源目录 resources下创建application.propertis文件,添加

server.port= 8081

2.类文件具有错误的版本 61.0, 应为 52.0

版本错误

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.8-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

 

posted @ 2018-06-25 22:42  jihite  阅读(318)  评论(0编辑  收藏  举报