启用https用于spring boot rest应用程序

时间:2016-01-27 15:10:38

标签: https spring-boot

使用https部署时,如何启用Spring引导应用程序? 我找到了一个解决方案,说明将以下内容添加到application-config.xml文件

   <security:http auto-config="true" create-session="stateless">
         <security:intercept-url pattern="/**" access="ROLE_USER"
                 requires-channel="https" />                      
          <security:http-basic />
   </security:http>

除了web.xml之外,我没有该文件;

<?xml version="1.0" encoding="UTF-8"?>
  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        
xmlns:web="http://java.sun.com/xml/ns/javaee" 
xmlns="
http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/
xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
 <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml,
    /WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener- class>
 </listener>
<listener>
<listener-class>
    org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>api</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>api</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
              org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

1 个答案:

答案 0 :(得分:0)

Spring Boot支持SSL配置属性(在application.yaml | .properties中)

server.port=8443
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=secret
server.ssl.key-password=another-secret

您可以使用TomcatEmbeddedServletContainerFactory执行相同的操作。

Documentation