博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring boot 使用https,并且http自动跳转https
阅读量:4228 次
发布时间:2019-05-26

本文共 1471 字,大约阅读时间需要 4 分钟。

配置使用https

springboot内部已经集成了,引入密钥文件,修改相关配置文件就可以使用https了,

server:  port: 8443  ssl:    key-store: classpath:www.aaa.cn.jks    key-store-password: aaaaaa    key-store-type: JKS

配置http跳转至https

监听一个http端口,请求这个跳转后请求会转发到对应的https端口

@Configurationpublic class CommonConfig {    @Value("${http.port}")    private Integer httpPort;    @Value("${server.port}")    private Integer serverPort;    @Bean    public TomcatServletWebServerFactory servletContainer() {        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {            @Override            protected void postProcessContext(Context context) {                SecurityConstraint constraint = new SecurityConstraint();                constraint.setUserConstraint("CONFIDENTIAL");                SecurityCollection collection = new SecurityCollection();                collection.addPattern("/*");                constraint.addCollection(collection);                context.addConstraint(constraint);            }        };        tomcat.addAdditionalTomcatConnectors(httpConnector());        return tomcat;    }    @Bean    public Connector httpConnector() {        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");        connector.setScheme("http");        //Connector监听的http的端口号        connector.setPort(8080);        connector.setSecure(false);        //监听到http的端口号后转向到的https的端口号        connector.setRedirectPort(8443);        return connector;    }}

就这么简单就完成了。

转载地址:http://dhjqi.baihongyu.com/

你可能感兴趣的文章
Performance Analysis of Communications Networks and Systems
查看>>
SQL Server CE Database Development with the .NET Compact Framework
查看>>
Service Design for Six Sigma: A Roadmap for Excellence
查看>>
Maximum Security (3rd Edition)
查看>>
Discovering Knowledge in Data: An Introduction to Data Mining
查看>>
Computer Applications in Pharmaceutical Research and Development
查看>>
Software Measurement and Estimation: A Practical Approach
查看>>
Microsoft SQL Server 2005 Express Edition For Dummies
查看>>
Excel Pivot Tables Recipe Book: A Problem-Solution Approach
查看>>
USB Mass Storage: Designing and Programming Devices and Embedded Hosts
查看>>
JDBC Metadata, MySQL, and Oracle Recipes: A Problem-Solution Approach
查看>>
From VBA to VSTO: Is Excel's New Engine Right for You?
查看>>
Sams Teach Yourself Data Structures and Algorithms in 24 Hours
查看>>
Professional Windows Desktop and Server Hardening
查看>>
Software Estimation: Demystifying the Black Art (Best Practices
查看>>
Handbook of Research on Mobile Multimedia
查看>>
SQLite (Developer's Library)
查看>>
Measuring Information Systems Delivery Quality
查看>>
Windows 2000 Performance Guide
查看>>
Ajax And Php: Building Responsive Web Applications
查看>>