栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java 发布https接口

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java 发布https接口

java 发布https接口
      • 证书生成命令:
      • 生成的证书 "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.p12
application.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.
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/531246.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号