- 浏览: 480199 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (502)
- Java (70)
- Linux (10)
- 数据库 (38)
- 网络 (10)
- WEB (13)
- JSP (4)
- 互联网 (71)
- JavaScript (30)
- Spring MVC (19)
- HTML (13)
- CSS (3)
- AngularJS (18)
- Redis (5)
- Bootstrap CSS (1)
- ZooKeeper (4)
- kafka (6)
- 服务器缓存 (4)
- Storm (1)
- MongoDB (9)
- Spring boot (16)
- log4j (2)
- maven (3)
- nginx (5)
- Tomcat (2)
- Eclipse (4)
- Swagger (2)
- Netty (5)
- Dubbo (1)
- Docker (7)
- Hadoop (12)
- OAuth (1)
- webSocket (4)
- 服务器性能 (7)
- Session共享 (1)
- tieye修改 (1)
- 工作 (1)
- 有用的语录 (0)
- https (2)
- common (5)
- 产品开发管理 (1)
- CDN 工作原理 (1)
- APNS、GCM (1)
- 架构图 (3)
- 功能实现分析 (1)
- JMX (1)
- 服务器相关操作命令 (1)
- img02 (0)
- 服务器环境搭建 (9)
- goodMenuBook (1)
- CEInstantPot (0)
- 有用数据 (1)
- 百度地图WEB API (2)
- 正则表达式 (1)
- 样式例子 (2)
- staticRecipePressureCooker.zip (1)
- jCanvas (1)
- 网站攻击方法原理 (1)
- 架构设计 (3)
- 物联网相关 (3)
- 研发管理 (7)
- 技术需求点 (1)
- 计划 (1)
- spring cloud (11)
- 服务器开发的一些实用工具和方法 (1)
- 每天学到的技术点 (4)
- Guava (1)
- ERP 技术注意要点 (2)
- 微信小程序 (1)
- FineRepor (1)
- 收藏夹 (1)
- temp (5)
- 服务架构 (4)
- 任职资格方案 (0)
- osno_test (1)
- jquery相关 (3)
- mybatis (4)
- ueditor (1)
- VueJS (7)
- python (10)
- Spring EL (1)
- shiro (1)
- 前端开发原理与使用 (7)
- YARN (1)
- Spark (1)
- Hbase (2)
- Pig (2)
- 机器学习 (30)
- matplotlib (1)
- OpenCV (17)
- Hystrix (1)
- 公司 (1)
- miniui (4)
- 前端功能实现 (3)
- 前端插件 (1)
- 钉钉开发 (2)
- Jenkins (1)
- elasticSearch使用 (2)
- 技术规范 (4)
- 技术实现原理 (0)
最新评论
Spring-boot中Http与Https兼容例子
1.证书生成参考:http://huangyongxing310.iteye.com/blog/2352693
application.properties
参考(在Spring Boot中使用Https(应用参考这个)):http://www.cnblogs.com/xinzhao/p/4952856.html
参考(Spring Boot基于Tomcat的HTTP和HTTPS协议配置,这个好):http://kchu.me/2015/08/19/Spring-Boot%E5%9F%BA%E4%BA%8ETomcat%E7%9A%84HTTP%E5%92%8CHTTPS%E5%8D%8F%E8%AE%AE%E9%85%8D%E7%BD%AE/
1.证书生成参考:http://huangyongxing310.iteye.com/blog/2352693
application.properties
#Server server.port=8090 #LOGGING logging.pattern.level=INFO #server.port:8443 #server.ssl.key-store: classpath:keystore.p12 ##server.ssl.key-store-password: aqjcpt #server.ssl.key-store-password:123456 #server.ssl.keyStoreType: PKCS12 #server.ssl.keyAlias: tomcat
package com.cesmart; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; @EnableAutoConfiguration @ComponentScan(basePackages = "com.cesmart") // 扫描那些包得到bean.@ComponentScan({"com.teradata.notification","com.teradata.dal"}) //@EnableSwagger2 //启动swagger注解 public class Application { public static void main(String[] args) { ApplicationContext applicationContext = SpringApplication.run(Application.class, args); } }
package com.cesmart.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import com.google.common.base.Predicates; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration//定义为spring boot 的配置文件 @EnableSwagger2//启动swagger注解 public class Swagger2 { public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.cesmart.controller"; @Bean(value="createRestApi") public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("test1") .pathMapping("/") .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE)) .paths(Predicates.or(PathSelectors.regex("/*/.*"))) .build(); //groupName,分组名字 //pathMapping,映射路径(会加到URL前面组成新的路径,如:"/xing/WebTest/webTest",(pathMapping("/xing"))) //apiInfo,API信息描述 //select, 选择那些路径和api会生成document //apis,扫描那些包,RequestHandlerSelectors.any()表示对所有api进行监控 //paths,匹配那些路径,PathSelectors.any()表示所有路径, } @Bean(value="createRestApi2") public Docket createRestApi2() { return new Docket(DocumentationType.SWAGGER_2) .groupName("test2") .pathMapping("/") .apiInfo(apiInfo2()) .select() .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE)) .paths(Predicates.or(PathSelectors.regex("/*/.*"))) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Spring Boot中使用Swagger2构建RESTful APIs") .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/") .termsOfServiceUrl("http://blog.didispace2.com/") .contact("程序猿DD") .version("1.0") .license("license") .licenseUrl("licenseUrl") .build(); //title,标题,在页面顶部显示 //description,描述,在页面顶部显示 //termsOfServiceUrl, //contact,显示“Created by + contact”,在页面顶部显示 //version,API版本,,在页面顶部显示 //license,版权 } private ApiInfo apiInfo2() { return new ApiInfoBuilder() .title("Spring Boot中使用Swagger2构建RESTful APIs") .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/") .termsOfServiceUrl("http://blog.didispace2.com/") .contact("程序猿DD") .version("1.0") .license("license") .licenseUrl("licenseUrl") .build(); } }
package com.cesmart.config; import java.io.File; import org.apache.catalina.Context; import org.apache.catalina.connector.Connector; import org.apache.tomcat.util.descriptor.web.SecurityCollection; import org.apache.tomcat.util.descriptor.web.SecurityConstraint; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.Ssl; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import com.google.common.base.Predicates; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration // 定义为spring boot 的配置文件 public class WebConfig { // Http访问的URL private static final String HTTP_URL_PATTERNS[] = { "/HttpTest/*" }; // Https访问的URL private static final String HTTPS_URL_PATTERNS[] = { "/HttpsTest/*" }; @Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { Ssl ssl = new Ssl(); // Server.jks中包含服务器私钥和证书 ssl.setKeyStore("classpath:keystore.p12"); ssl.setKeyStorePassword("123456"); container.setSsl(ssl); container.setPort(8443); } }; } @Bean public EmbeddedServletContainerFactory servletContainerFactory() { TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory() { @Override protected void postProcessContext(Context context) { // SecurityConstraint必须存在,可以通过其为不同的URL设置不同的重定向策略。 SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.setUserConstraint("CONFIDENTIAL"); SecurityCollection collection = new SecurityCollection(); for (String pattern : HTTPS_URL_PATTERNS) { collection.addPattern(pattern); } securityConstraint.addCollection(collection); context.addConstraint(securityConstraint); // ============== SecurityConstraint securityConstraintHttp = new SecurityConstraint(); securityConstraintHttp.setUserConstraint("NONE"); SecurityCollection collectionHttp = new SecurityCollection(); for (String pattern : HTTP_URL_PATTERNS) { collectionHttp.addPattern(pattern); } securityConstraintHttp.addCollection(collectionHttp); context.addConstraint(securityConstraintHttp); } }; factory.addAdditionalTomcatConnectors(createHttpConnector()); return factory; } private Connector createHttpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setSecure(false); connector.setPort(8090); connector.setRedirectPort(8443); return connector; } }
package com.cesmart.controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @RestController @Api(value = "HttpsTest", description = "有关于HttpsTest操作") @RequestMapping(value = "/HttpsTest") // 用在类上,说明该类的作用 // value,显示在类中的说明 // description,类中的说明 // 显示形式:“value:description”,如上面显示为"WebTest:有关于Swagger2操作" public class HttpsTest { @ApiOperation(value = "接口说明", notes = "接口发布说明", response = String.class) // 用在方法上,说明方法的作用 // 显示在方法说明中,显示notes // response,接口返回参数类型 // value = "接口说明", // notes = "接口发布说明" @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", required = true, name = "test", dataType = "String", value = "456"), @ApiImplicitParam(paramType = "path", required = true, name = "test2", dataType = "String", value = "789") }) // @ApiImplicitParam,表示一个参数的描述,与请求参数有关系 // paramType,参数放在哪个地方 // required,参数是否必须传 // name,参数名 // dataType,参数类型(描述) // value,参数的意思(描述) @ApiParam @RequestMapping(value = "/HttpsTestGet/{test}/{test2}", produces = "text/plain;charset=UTF-8", method = RequestMethod.GET) public String HttpsTestGet(@PathVariable("test") String test, @PathVariable("test2") String test2) { System.out.println("HttpTest"); System.out.println("test == " + test); System.out.println("test2 == " + test2); return "HttpTest"; } @ApiOperation(value = "接口说明", notes = "接口发布说明", response = String.class) @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", required = true, name = "test", dataType = "String", value = "456", defaultValue = "test"), @ApiImplicitParam(paramType = "query", required = true, name = "test2", dataType = "String", value = "789", defaultValue = "test2") }) @RequestMapping(value = "/HttpsTestPost", produces = "text/plain;charset=UTF-8", method = RequestMethod.POST) public String HttpsTestPost(String test, String test2) { System.out.println("webTest"); System.out.println("test == " + test); System.out.println("test2 == " + test2); return "webTest"; } }
package com.cesmart.controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @RestController @Api(value = "HttpTest", description = "有关于HttpTest操作") @RequestMapping(value = "/HttpTest") // 用在类上,说明该类的作用 // value,显示在类中的说明 // description,类中的说明 // 显示形式:“value:description”,如上面显示为"WebTest:有关于Swagger2操作" public class HttpTest { @ApiOperation(value = "接口说明", notes = "接口发布说明", response = String.class) // 用在方法上,说明方法的作用 // 显示在方法说明中,显示notes // response,接口返回参数类型 // value = "接口说明", // notes = "接口发布说明" @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", required = true, name = "test", dataType = "String", value = "456"), @ApiImplicitParam(paramType = "path", required = true, name = "test2", dataType = "String", value = "789") }) // @ApiImplicitParam,表示一个参数的描述,与请求参数有关系 // paramType,参数放在哪个地方 // required,参数是否必须传 // name,参数名 // dataType,参数类型(描述) // value,参数的意思(描述) @ApiParam @RequestMapping(value = "/HttpTestGet/{test}/{test2}", produces = "text/plain;charset=UTF-8", method = RequestMethod.GET) public String HttpTestGet(@PathVariable("test") String test, @PathVariable("test2") String test2) { System.out.println("HttpTest"); System.out.println("test == " + test); System.out.println("test2 == " + test2); return "HttpTest"; } @ApiOperation(value = "接口说明", notes = "接口发布说明", response = String.class) @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", required = true, name = "test", dataType = "String", value = "456", defaultValue = "test"), @ApiImplicitParam(paramType = "query", required = true, name = "test2", dataType = "String", value = "789", defaultValue = "test2") }) @RequestMapping(value = "/HttpTestPost", produces = "text/plain;charset=UTF-8", method = RequestMethod.POST) public String HttpTestPost(String test, String test2) { System.out.println("webTest"); System.out.println("test == " + test); System.out.println("test2 == " + test2); return "webTest"; } }
参考(在Spring Boot中使用Https(应用参考这个)):http://www.cnblogs.com/xinzhao/p/4952856.html
参考(Spring Boot基于Tomcat的HTTP和HTTPS协议配置,这个好):http://kchu.me/2015/08/19/Spring-Boot%E5%9F%BA%E4%BA%8ETomcat%E7%9A%84HTTP%E5%92%8CHTTPS%E5%8D%8F%E8%AE%AE%E9%85%8D%E7%BD%AE/
发表评论
-
每天学到的技术点3
2022-02-21 20:01 2211.TEXT与BLOB的区别,二者 ... -
springboot tomcat 参数配置与数据库连接池多少的性能分析
2021-05-12 22:15 529参数配置与数据库连接池多少的性能分析 tomcat线程数 ... -
springBoot tomcat配置参数说明
2021-05-12 09:13 2934#最大连接数 server.tomcat.max-connec ... -
log4j2应用
2020-07-23 14:16 338https://blog.csdn.net/giventian ... -
文件上传下载
2020-07-06 13:16 3641.文件ID,名字(源,目标),大小,路径(/aa/bb/s. ... -
Spring Boot中整合Sharding-JDBC
2018-11-26 18:03 3416Spring Boot中整合Sharding-JDBC ... -
spring boot 集成 shiro
2018-08-06 10:01 454spring boot 集成 shiro shiro(权限 ... -
spring oauth2.0
2017-07-07 18:12 1595spring oauth2.0 grant_type : a ... -
spring security
2017-07-07 17:18 886spring security security,就是实现了一 ... -
oneAPM 在SpringBoot中的应用
2017-02-28 11:23 934oneAPM 在SpringBoot中的应用 下载 One ... -
SpringBootJsp例子
2017-02-22 19:52 379SpringBootJsp例子 -
Https 在spring-boot应用例子
2017-01-12 17:45 982Https 在spring-boot应用例 ... -
Spring Boot webSocket应用例子
2016-11-25 16:20 1007Spring Boot webSocket应用例子 后端代 ... -
Spring boot Properties文件读取
2016-10-18 14:09 779Spring boot Properties文件读取 @C ... -
Spring boot 简单例子
2016-10-18 11:33 559Spring boot 简单例子 application. ...
相关推荐
赠送jar包:seata-spring-boot-starter-1.3.0.jar; 赠送原API文档:seata-spring-boot-starter-1.3.0-javadoc.jar; 赠送源代码:seata-spring-boot-starter-1.3.0-sources.jar; 赠送Maven依赖信息文件:seata-...
赠送jar包:mybatis-spring-boot-autoconfigure-1.3.2.jar; 赠送原API文档:mybatis-spring-boot-autoconfigure-1.3.2-javadoc.jar; 赠送源代码:mybatis-spring-boot-autoconfigure-1.3.2-sources.jar; 赠送...
赠送jar包:druid-spring-boot-starter-1.1.9.jar; 赠送原API文档:druid-spring-boot-starter-1.1.9-javadoc.jar; 赠送源代码:druid-spring-boot-starter-1.1.9-sources.jar; 赠送Maven依赖信息文件:druid-...
赠送jar包:druid-spring-boot-starter-1.1.10.jar; 赠送原API文档:druid-spring-boot-starter-1.1.10-javadoc.jar; 赠送源代码:druid-spring-boot-starter-1.1.10-sources.jar; 赠送Maven依赖信息文件:druid-...
赠送jar包:spring-boot-actuator-autoconfigure-2.3.12.RELEASE.jar; 赠送原API文档:spring-boot-actuator-autoconfigure-2.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-boot-actuator-autoconfigure-2.3.12....
赠送jar包:aliyun-sms-spring-boot-starter-2.0.2.jar 赠送原API文档:aliyun-sms-spring-boot-starter-2.0.2-javadoc.jar 赠送源代码:aliyun-sms-spring-boot-starter-2.0.2-sources.jar 包含翻译后的API文档...
赠送jar包:spring-boot-autoconfigure-2.3.12.RELEASE.jar; 赠送原API文档:spring-boot-autoconfigure-2.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-boot-autoconfigure-2.3.12.RELEASE-sources.jar; 赠送...
赠送jar包:dynamic-datasource-spring-boot-starter-3.4.1.jar; 赠送原API文档:dynamic-datasource-spring-boot-starter-3.4.1-javadoc.jar; 赠送源代码:dynamic-datasource-spring-boot-starter-3.4.1-sources...
赠送jar包:spring-boot-configuration-processor-2.6.3.jar; 赠送原API文档:spring-boot-configuration-processor-2.6.3-javadoc.jar; 赠送源代码:spring-boot-configuration-processor-2.6.3-sources.jar; ...
赠送jar包:oss-spring-boot-starter-1.0.3.jar; 赠送原API文档:oss-spring-boot-starter-1.0.3-javadoc.jar; 赠送源代码:oss-spring-boot-starter-1.0.3-sources.jar; 赠送Maven依赖信息文件:oss-spring-boot...
赠送jar包:dynamic-datasource-spring-boot-starter-3.4.1.jar; 赠送原API文档:dynamic-datasource-spring-boot-starter-3.4.1-javadoc.jar; 赠送源代码:dynamic-datasource-spring-boot-starter-3.4.1-sources...
赠送jar包:nacos-config-spring-boot-autoconfigure-0.2.7.jar; 赠送原API文档:nacos-config-spring-boot-autoconfigure-0.2.7-javadoc.jar; 赠送源代码:nacos-config-spring-boot-autoconfigure-0.2.7-sources...
赠送jar包:spring-boot-configuration-processor-2.3.12.RELEASE.jar; 赠送原API文档:spring-boot-configuration-processor-2.3.12.RELEASE-javadoc.jar; 赠送源代码:spring-boot-configuration-processor-...
赠送jar包:spring-boot-configuration-processor-2.5.6.jar; 赠送原API文档:spring-boot-configuration-processor-2.5.6-javadoc.jar; 赠送源代码:spring-boot-configuration-processor-2.5.6-sources.jar; ...
赠送jar包:druid-spring-boot-starter-1.2.8.jar; 赠送原API文档:druid-spring-boot-starter-1.2.8-javadoc.jar; 赠送源代码:druid-spring-boot-starter-1.2.8-sources.jar; 赠送Maven依赖信息文件:druid-...
赠送jar包:aliyun-sms-spring-boot-starter-2.0.2.jar; 赠送原API文档:aliyun-sms-spring-boot-starter-2.0.2-javadoc.jar; 赠送源代码:aliyun-sms-spring-boot-starter-2.0.2-sources.jar; 赠送Maven依赖信息...
赠送jar包:druid-spring-boot-starter-1.1.9.jar; 赠送原API文档:druid-spring-boot-starter-1.1.9-javadoc.jar; 赠送源代码:druid-spring-boot-starter-1.1.9-sources.jar; 赠送Maven依赖信息文件:druid-...
赠送jar包:oss-spring-boot-starter-1.0.3.jar 赠送原API文档:oss-spring-boot-starter-1.0.3-javadoc.jar 赠送源代码:oss-spring-boot-starter-1.0.3-sources.jar 包含翻译后的API文档:oss-spring-boot-...
赠送jar包:jasypt-spring-boot-3.0.4.jar; 赠送原API文档:jasypt-spring-boot-3.0.4-javadoc.jar; 赠送源代码:jasypt-spring-boot-3.0.4-sources.jar; 赠送Maven依赖信息文件:jasypt-spring-boot-3.0.4.pom;...
赠送jar包:spring-boot-2.2.8.RELEASE.jar; 赠送原API文档:spring-boot-2.2.8.RELEASE-javadoc.jar; 赠送源代码:spring-boot-2.2.8.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-boot-2.2.8.RELEASE....