1. 需要建立父子maven结构

    springboot2.1.5-https和http访问-LMLPHP

    1. 父maven pom文件

      	<?xml version="1.0" encoding="UTF-8"?>
      	<project xmlns="http://maven.apache.org/POM/4.0.0"
      			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      			 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      		<modelVersion>4.0.0</modelVersion>
      
      		<groupId>tom.heliming.cloud</groupId>
      		<artifactId>cloud-demo</artifactId>
      		<packaging>pom</packaging>
      		<version>1.0-SNAPSHOT</version>
      		<modules>
      			<!--<module>oracle</module>-->
      			<!--<module>mongodb</module>-->
      			<!--<module>okhttp</module>-->
      			<!--<module>netty-demo</module>-->
      			<!--<module>mysqldemo</module>-->
      			<!--<module>rabbitmq</module>-->
      			<!--<module>memcache</module>-->
      			<!--<module>tarsdemo</module>-->
      			<!--<module>agentdemo</module>-->
      			<!--<module>netty</module>-->
      			<!--<module>mybatis</module>-->
      			<!--<module>avro</module>-->
      			<!--<module>mina</module>-->
      			<module>redis</module>
      			<!--<module>quartz</module>-->
      			<!--<module>jvm</module>-->
      			<!--<module>activemq</module>-->
      		</modules>
      		<parent>
      			<groupId>org.springframework.boot</groupId>
      			<artifactId>spring-boot-starter-parent</artifactId>
      			<version>2.1.5.RELEASE</version>
      			<relativePath/> <!-- lookup parent from repository -->
      		</parent>
      		<properties>
      			<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      			<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      			<maven.compiler.source>1.8</maven.compiler.source>
      			<maven.compiler.target>1.8</maven.compiler.target>
      			<java.version>1.8</java.version>
      		</properties>
      		<dependencies>
      
      			<!-- Spring Boot相关依赖 -->
      			<dependency>
      				<groupId>org.springframework.boot</groupId>
      				<artifactId>spring-boot-starter</artifactId>
      			</dependency>
      			<dependency>
      				<groupId>org.springframework.boot</groupId>
      				<artifactId>spring-boot-starter-web</artifactId>
      				<exclusions>
      					<exclusion>
      						<groupId>org.springframework.boot</groupId>
      						<artifactId>spring-boot-starter-tomcat</artifactId>
      					</exclusion>
      				</exclusions>
      			</dependency>
      			<!--war包方式-->
      			<dependency>
      				<groupId>org.springframework.boot</groupId>
      				<artifactId>spring-boot-starter-tomcat</artifactId>
      				<!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
      					相当于compile,但是打包阶段做了exclude操作-->
      				<scope>provided</scope>
      			</dependency>
      		   <!-- 不加这个是因为加了这个只能加上tomcat之类的容器启动不能用java -jar *.war启动 -->
      			<!--<dependency>-->
      				<!--<groupId>javax.servlet</groupId>-->
      				<!--<artifactId>servlet-api</artifactId>-->
      				<!--<version>2.5</version>-->
      			<!--</dependency>-->
      			<!--<dependency>-->
      				<!--<groupId>org.springframework.boot</groupId>-->
      				<!--<artifactId>spring-boot-starter-jetty</artifactId>-->
      			<!--</dependency>-->
      
      			<dependency>
      				<groupId>org.springframework.boot</groupId>
      				<artifactId>spring-boot-starter-test</artifactId>
      				<!-- <scope>test</scope>-->
      			</dependency>
      
      
      		</dependencies>
      
      	</project>
      
  2. 子maven项目结构

    springboot2.1.5-https和http访问-LMLPHP

    1. 子maven pom文件

      	<?xml version="1.0" encoding="UTF-8"?>
      	<project xmlns="http://maven.apache.org/POM/4.0.0"
      			 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      			 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      		<parent>
      			<artifactId>cloud-demo</artifactId>
      			<groupId>tom.heliming.cloud</groupId>
      			<version>1.0-SNAPSHOT</version>
      		</parent>
      		<modelVersion>4.0.0</modelVersion>
      
      		<groupId>tom.heliming.redis</groupId>
      		<artifactId>redis</artifactId>
      		<dependencies>
      
      			<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
      			<dependency>
      				<groupId>redis.clients</groupId>
      				<artifactId>jedis</artifactId>
      				<version>2.9.0</version>
      			</dependency>
      		</dependencies>
      		<!-- 打包设置启动springboot的main函数 -->
      		<build>
      			<finalName>redis</finalName>
      			<plugins>
      				<plugin>
      					<groupId>org.springframework.boot</groupId>
      					<artifactId>spring-boot-maven-plugin</artifactId>
      					<executions>
      						<execution>
      							<goals>
      								<goal>repackage</goal>
      							</goals>
      						</execution>
      					</executions>
      					<configuration>
      						<includeSystemScope>true</includeSystemScope>
      					</configuration>
      				</plugin>
      			</plugins>
      		</build>
      
      	</project>
      
    2. 生成证书(server.jks)放到项目的resources下config下

       keytool -genkeypair -alias springboot -keyalg RSA -dname "CN=SERVER1,OU=Unit,O=Elim,L=City,S=Province,C=CN" -keypass 123456 -keystore server.jks -storepass 123456 -storetype jks
      
    3. application.yml

      	server:
      	  port: 8443
      	  ssl:
      		enabled: true
      		key-alias: springboot
      		key-password: 123456
      		key-store-password: 123456
      		key-store: classpath:config/server.jks
      		key-store-type: JKS
      
    4. RedisApp.java

      	package top;
      
      	import org.springframework.boot.SpringApplication;
      	import org.springframework.boot.autoconfigure.SpringBootApplication;
      
      	/**
      	 * description:
      	 *
      	 * @author: dawn.he QQ:       905845006
      	 * @email: dawn.he@cloudwise.com
      	 * @email: 905845006@qq.com
      	 * @date: 2019/9/6    10:07 AM
      	 */
      	@SpringBootApplication
      	public class RedisApp {
      
      		public static void main(String[] args) {
      			SpringApplication.run(RedisApp.class,args);
      		}
      	}
      
    5. TomcatConfiguration.java

      	package top.conf;
      
      	import org.apache.catalina.connector.Connector;
      	import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
      	import org.springframework.context.annotation.Bean;
      	import org.springframework.context.annotation.Configuration;
      
      	/**
      	 * description:
      	 *
      	 * @author: dawn.he QQ:       905845006
      	 * @email: dawn.he@cloudwise.com
      	 * @email: 905845006@qq.com
      	 * @date: 2019/9/27    8:41 AM
      	 */
      	@Configuration
      	public class TomcatConfiguration {
      
      		@Bean
      		public TomcatServletWebServerFactory servletContainer(){
      			TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
      			tomcat.addAdditionalTomcatConnectors(this.httpConnector());
      			return tomcat;
      		}
      
      		private Connector httpConnector(){
      			Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
      			connector.setScheme("http");
      			connector.setPort(8081);
      			connector.setSecure(false);
      			return connector;
      		}
      
      	}
      
    6. HelloController.java

      	package top.web;
      
      	import org.springframework.http.HttpStatus;
      	import org.springframework.http.ResponseEntity;
      	import org.springframework.web.bind.annotation.GetMapping;
      	import org.springframework.web.bind.annotation.RequestMapping;
      	import org.springframework.web.bind.annotation.RestController;
      
      	import static top.activemq.util.RedisUtil.redisdemo;
      
      	/**
      	 * description:
      	 *
      	 * @author: dawn.he QQ:       905845006
      	 * @email: dawn.he@cloudwise.com
      	 * @email: 905845006@qq.com
      	 * @date: 2019/9/6    10:56 AM
      	 */
      	@RestController
      	@RequestMapping("/redis")
      	public class HelloController {
      
      		@GetMapping("/all")
      		public ResponseEntity<String> hello() throws InterruptedException {
      
      			try {
      				int i = 1/0;
      				redisdemo();
      
      			}catch (Exception e ){
      				System.out.println("-----");
      
      			}
      	//        return "redis:success";
      
      			return new ResponseEntity<String>("sss",HttpStatus.INTERNAL_SERVER_ERROR);
      		}
      	}
      

    访问:

    http://localhost:8081/redis/all

    https://localhost:8443/redis/all

    springboot不同版本参考:https://blog.csdn.net/elim168/article/details/92689604https://memorynotfound.com/spring-boot-configure-tomcat-ssl-https/

    后期改为阿里云生成的证书,暂时用jdk生成的。

09-27 13:06