- 证书生成命令:
- 生成的证书 "keystore.p12" 放到resources目录下:
- application.yml 配置文件添加:
- pom.xml依赖
- 编写测试类:
- 启动项目后,访问地址:
keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650生成的证书 “keystore.p12” 放到resources目录下:
├─main │ ├─java │ │ └─com │ │ └─xasj │ │ └─cpsscheduler │ └─resources │ ├─static │ └─templates │ └─keystore.p12application.yml 配置文件添加:
server:
port: 8000
ssl:
key-store: classpath:keystore.p12
key-store-password: 123456
key-store-type: PKCS12
key-alias: tomcat
pom.xml依赖
编写测试类:4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.6 com.xasj cps-scheduler 1.0.0 cps-scheduler cps接口调用服务 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime true org.springframework.boot spring-boot-configuration-processor true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok repackage org.apache.maven.plugins maven-compiler-plugin 3.8.1 UTF-8 1.8 1.8
@RestController
public class TestController {
@GetMapping("/test")
public Map testMap(){
Map map = new HashMap(2);
map.put("1","a");
map.put("2","b");
return map;
}
}
启动项目后,访问地址:
https://127.0.0.1:8000/test
响应结果:
{
"1": "a",
"2": "b"
}
访问地址:
http://127.0.0.1:8000/test
响应结果:
Bad Request This combination of host and port requires TLS.



