首页 > 编程语言 > 详细

Spring boot启动Https( 全流程,参考若干资料)

时间:2017-02-23 16:18:23      阅读:298      评论:0      收藏:0      [点我收藏+]

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>

 到此才能完全搞定https。

可怜我修改了半天啊。

 

Spring boot启动Https( 全流程,参考若干资料)

原文:http://www.cnblogs.com/lixiaopei/p/6433513.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!