Hello Spring Boot

基于Spring Boot构建的应用程序有以下特点
  • 快、很快、非常快
  • 进可开箱即用,退可按需改动
  • 提供各种非功能特性
  • 不用生成代码,没有XML配置
Hello-Spring
  • 编写第一个Spring程序,打开spring网站
  • 选择Maven Project、Java、Spring Boot的版本、Group和Artifact的信息、添加Search dependencies to add等信息如下图,最后点击Generate Project下载压缩包

  • 将压缩包解压,用IDEA打开该项目,打开后的项目结构如下图:

示意图

  • 编写第一行代码
package com.zxw.hello.hellospring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class HelloSpringApplication {

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

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

运行该项目,打开Terminal输入

 curl http://localhost:8080/hello 

就会返回(如下图)

Hello Spring%  

在这里插入图片描述

在Terminal输入

curl http://localhost:8080/actuator/health
得到结果
{"status":"UP"}%
可以检查程序是否正常

执行打包:在Terminal中输入命令:

mvn clean package -Dmaven.test.skip
打包完成后输入:ls 
得到返回结果:
HELP.md          hello-spring.iml mvnw             mvnw.cmd         pom.xml          src              target

再输入:cd target
得到返回结果:
lasses                                  hello-spring-0.0.1-SNAPSHOT.jar          maven-archiver
generated-sources                        hello-spring-0.0.1-SNAPSHOT.jar.original maven-status

这样就可以得到可执行的jar包用java -jar 就可以运行这个程序如:
java -jar hello-spring-0.0.1-SNAPSHOT.jar


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值