1、spring-boot学习笔记(一)简单入门

此页面是否是列表页或首页?未找到合适正文内容。

1、spring-boot学习笔记(一)简单入门

标签:url路径ble通过cattarrestint学习world

一、新建普通Maven工程

pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>SpringBoot001_HelloWorld</finalName>
</build>
二、编写代码
@SpringBootApplication
@RestController
public class Application
{
@RequestMapping("/hello")
public String hello(){
return "hello world";
}
@RequestMapping("/geeting")
public String geeting(){
return "Index page";
}

@RequestMapping("/geeting/{user}")
public String get(@PathVariable("user") String name ){
if(name.equals("zhangsan")){
return name+" Hello";
}
return "hello";
}
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}

**@SpringBootApplication** :指定是否为SpringBoot应用

**@RestContrller** :这个一般加在类上,说明这是一个Rest应用,每个方法返回的不再是视图

**@RequestMapping** :url路径映射

**@PathVariable** :读取路径中的变量值 赋值给name

三、代码执行

直接先mvn package 打出jar包 在命令行中执行 java -jar jar包路径

以下内容作为了解即可;等到世纪应用的时候看下

四、停止

1)、强制停止
ps aux | grep spring | xargs kill -9
2)、通过前台停止

pom文件加入

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

application.yml 加入

#启用shutdown
endpoints:
shutdown:
enabled: true
#禁用密码验证
sensitive: false
3)、加入密码验证

pom.xml加入

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

application.properties加入

#开启shutdown的安全验证
endpoints.shutdown.sensitive=true

#验证用户名
security.user.name=admin

#验证密码
security.user.password=admin
#角色
management.security.role=SUPERUSER

# 指定端口
management.port=8081

# 指定地址
management.address=127.0.0.1
4)关闭命令
curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown

# Demo

$ curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown
{"message":"Shutting down, bye…"}

1、spring-boot学习笔记(一)简单入门

标签:url路径ble通过cattarrestint学习world

原文地址:https://www.cnblogs.com/irich/p/8719655.html

作者: 雨林木风

为您推荐

返回顶部