【发布时间】:2018-04-12 08:48:05
【问题描述】:
我正在将一个旧的 java spring 项目重构为 springboot,并以传统的战争风格进行部署。出于某种原因,我必须坚持使用传统的 web.xml 来启动应用程序。感谢 Springboot legacy,我可以通过 web.xml 实现这一点:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.MyServerServletConfig</param-value>
</context-param>
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
另外,我添加了springboot执行器依赖。 application.properties 如下:
endpoints.enabled=true
endpoints.sensitive=true
management.security.enabled=true
management.context-path=/manage
security.user.password=myserver
security.user.name=myserver
应用程序可以正常启动,但是当我尝试从浏览器访问端点时,它只返回一个401 Full authentication is required to access this resource 错误,而不要求我输入用户名和密码。相关日志如下:
16:00:04.264 DEBUG [resin-port-8081-19] org.springframework.web.servlet.DispatcherServlet: DispatcherServlet with name 'myservlet' processing GET request for [/manage/health]
16:00:04.264 DEBUG [resin-port-8081-19] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping: Looking up handler method for path /manage/health
16:00:04.264 DEBUG [resin-port-8081-19] org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping: Returning handler method [public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)]
16:00:04.264 DEBUG [resin-port-8081-19] org.springframework.web.servlet.DispatcherServlet: Last-Modified value for [/manage/health] is: -1
16:00:04.264 DEBUG [resin-port-8081-19] org.springframework.core.env.PropertySourcesPropertyResolver: Found key 'endpoints.sensitive' in [applicationConfig: [classpath:../conf/application.properties]] with type [String]
16:00:04.265 DEBUG [resin-port-8081-19] org.springframework.web.servlet.DispatcherServlet: Successfully completed request
这个问题的原因可能是什么? springboot 自动构建的 DispatherServlet 与 web.xml 中明确定义的 DispatherServlet 之间有什么区别吗?出于安全考虑,management.security.enabled=true 是必须的。
【问题讨论】:
标签: spring spring-boot spring-security spring-boot-actuator