Spring boot启动Https

Spring boot内置Tomcat上支持Https端口。

步骤:

1. 生成证书或者从机构购买证书

下面生成自定义的证书

复制代码
keytool -genkey -alias tomcat  -storetype PKCS12 -keyalg RSA -keysize 2048  -keystore keystore.p12 -validity 3650

Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]:
What is the name of your organizational unit?
[Unknown]:
What is the name of your organization?
[Unknown]:
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
[no]: yes
复制代码

 

2. 把证书添加到项目中

    将生成的keystore.p12放入到资源文件夹下面。具体放在哪里呢?

    我的项目是放在: src/main/resources下面

3. 修改Spring-boot的配置文件,打开https

    在yml配置文件中,使用证书,打开https:    

复制代码
server:
  port: 12002
  ssl:
    key-store: classpath:keystore.p12
    key-store-password: peipei123
    keyStoreType: PKCS12
    keyAlias: tomcat
复制代码

 

4. 编译,启动,用浏览器访问。(这个地方最坑爹了)

    直接编译,启动。一般到这个地方就没问题。

    但是但是,我那个倒霉蛋啊。我就是启动不了。

    最后查了一下,为什么呢?

    我们实际使用的keystore.p12正式是我们真的keystore.p12吗?

     修改pom.xml,告诉丫,build的时候别修改我的证书。

      

复制代码
<plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-resources-plugin</artifactId>
                 <configuration>
                        <encoding>UTF-8</encoding>
                        <!-- 过滤后缀为pem、pfx的证书文件 -->
                        <nonFilteredFileExtensions>
                                <nonFilteredFileExtension>pem</nonFilteredFileExtension>
                                <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
                                <nonFilteredFileExtension>p12</nonFilteredFileExtension>
                        </nonFilteredFileExtensions>
                </configuration>
            </plugin>
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值