“Spring Boot-HelloWorld”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第83行: 第83行:
  
 
</syntaxhighlight>测试URL:http://localhost:8080/hello
 
</syntaxhighlight>测试URL:http://localhost:8080/hello
 +
 +
 +
 +
 +
=== Application.yml ===
 +
 +
==== 修改 tomcat 监听端口 ====
 +
<syntaxhighlight lang="yaml">
 +
server:
 +
  port: 8888
 +
</syntaxhighlight>
 +
 +
 +
 +
==== 官方文档配置属性说明 ====
 +
https://docs.spring.io/spring-boot/docs/2.7.8/reference/html/application-properties.html#appendix.application-properties

2023年2月1日 (三) 06:24的版本

Spring Boot 2 入门

系统要求

Java 8 & 兼容 java 14

Maven 3.3+

idea 2019.12

maven 设置

<mirrors>
    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>jdk-1.8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
    </profile>
</profiles>

https://www.bilibili.com/video/BV19K4y1L7MT?p=5



Java代码

MainApplication.java

package io.github.jihch.boot;

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


/**
 * 主程序类
 * @SpringBootApplication:这是一个 Spring Boot 应用
 */
@SpringBootApplication
public class MainApplication {

    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }

}


HelloController.java

package io.github.jihch.boot.controller;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String handle01() {
        return "Hello, Spring Boot 2!";
    }

}

测试URL:http://localhost:8080/hello



Application.yml

修改 tomcat 监听端口

server:
  port: 8888


官方文档配置属性说明

https://docs.spring.io/spring-boot/docs/2.7.8/reference/html/application-properties.html#appendix.application-properties