- 证书生成命令:
- 生成的证书 "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: tomcatpom.xml依赖
编写测试类:4.0.0 org.springframework.boot spring-boot-starter-parent2.5.6 com.xasj cps-scheduler1.0.0 cps-scheduler cps接口调用服务 1.8 org.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-devtoolsruntime true org.springframework.boot spring-boot-configuration-processortrue org.projectlombok lomboktrue org.springframework.boot spring-boot-starter-testtest org.springframework.boot spring-boot-maven-pluginorg.projectlombok lombokrepackage org.apache.maven.plugins maven-compiler-plugin3.8.1 UTF-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.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)