我正在将一个旧的java spring项目重构为springboot,并以传统的war风格部署它。由于某种原因,我必须坚持使用传统的 web.xml 来启动应用程序。感谢 Springboot 的遗留,我可以通过 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>
Run Code Online (Sandbox Code Playgroud)
另外,我添加了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
Run Code Online (Sandbox Code Playgroud)
应用程序可以正常启动,但是当我尝试从浏览器访问端点时,它只是返回错误,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 …Run Code Online (Sandbox Code Playgroud)