我有一个带有以下启动代码的Spring启动应用程序。 Actuator端点被映射并且bean被移除。我看到执行器端点已注册,然后移除了豆子。通过SO thread,消息是无害的。但是当我试图达到任何执行器终点时,我会收到错误。我不确定我应该进一步研究如何使执行器工作。我附上了我所指的所有日志片段。
我使用maven进行项目设置:
Maven Spring Actuator部分
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
Java启动代码
@EnableAutoConfiguration(exclude = { MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class, MessageSourceAutoConfiguration.class })
@EnableConfigurationProperties({ MyAppProperties.class })
@SpringBootApplication
public class MyApp{
private static final Logger LOG = LoggerFactory.getLogger(MyApp.class);
public static void main(String[] args) throws UnknownHostException {
SpringApplication app = new SpringApplication(MyApp.class);
Environment env = app.run(args).getEnvironment();
LOG.info("\n----------------------------------------------------------\n\t" +
"Application '{}' is running! Access URLs:\n\t" +
"Local: \t\thttp://localhost:{}\n\t" +
"External: \thttp://{}:{}\n----------------------------------------------------------",
env.getProperty("spring.application.name"),
env.getProperty("server.port"),
InetAddress.getLocalHost().getHostAddress(),
env.getProperty("server.port"));
}
}
执行器根据登录DEBUG模式启动端点:
2017-03-17 11:19:29.378 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-03-17 11:19:29.379 DEBUG 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : 1 request handler methods found on class org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint: {public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException={[],methods=[GET],produces=[application/octet-stream]}}
2017-03-17 11:19:29.379 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2017-03-17 11:19:29.380 DEBUG 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : 1 request handler methods found on class org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter: {public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()={[],methods=[GET],produces=[application/json]}}
2017-03-17 11:19:29.380 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-03-17 11:19:29.384 DEBUG 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : 2 request handler methods found on class org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint: {public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)={[/{name:.*}],methods=[GET],produces=[application/json]}, public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()={[],methods=[GET],produces=[application/json]}}
2017-03-17 11:19:29.384 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2017-03-17 11:19:29.384 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-03-17 11:19:29.384 DEBUG 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : 1 request handler methods found on class org.springframework.cloud.context.restart.RestartMvcEndpoint: {public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()={[],methods=[POST]}}
2017-03-17 11:19:29.384 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/restart || /restart.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()
2017-03-17 11:19:29.386 INFO 17855 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-03-17 11:19:29.386 DEBUG 17855 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Finished creating instance of bean 'endpointHandlerMapping'
2017-03-17 11:19:29.386 DEBUG 17855 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : Autowiring by type from bean name 'org.springframework.boot.actuate.autoconfigure.EndpointWebMvcChildContextConfiguration$EndpointHandlerMappingConfiguration' to bean named 'mvcEndpoints'
最终我在日志中看到豆被移除了:
2017-03-17 11:19:29.415 DEBUG 17855 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'endpointHandlerMapping': no URL paths identified
2017-03-17 11:19:29.415 DEBUG 17855 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'mvcEndpoints': no URL paths identified
2017-03-17 11:19:29.415 DEBUG 17855 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'environmentMvcEndpoint': no URL paths identified
2017-03-17 11:19:29.415 DEBUG 17855 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'heapdumpMvcEndpoint': no URL paths identified
2017-03-17 11:19:29.415 DEBUG 17855 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'healthMvcEndpoint': no URL paths identified
2017-03-17 11:19:29.415 DEBUG 17855 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'metricsMvcEndpoint': no URL paths identified
当我向/info
或/health
发出请求以达到信息和健康状况时,我会被定向到whitelabel错误页面,因为找不到处理程序。
调试调度程序servlet后,我发现有7个处理程序,我希望在/info
中找到BeanNameUrlHandlerMapping
的映射。
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WelcomePageHandlerMapping
由于列表中的第一个映射是SimpleUrlHandlerMapping
,它会立即返回“no handler mapping”,这会将我带到错误页面。我尝试检查顺序是否重要并查看BeanNameUrlHandlerMapping
以查看它是否返回处理程序映射并且它没有返回任何内容。所以我怀疑早先删除bean的调试消息是导致问题的罪魁祸首。
有人可以建议我是否需要特别注意。
答案 0 :(得分:3)
根据入门指南:Building a RESTful Web Service with Spring Boot Actuator您应该使用spring-boot-starter-actuator
首发:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
而不是spring-boot-actuator
依赖。
另请注意,根据Spring Boot reference:
HealthIndicators返回的信息通常在某种程度上是敏感的。例如,您可能不希望向全世界发布数据库服务器的详细信息。因此,默认情况下,仅通过未经身份验证的HTTP连接公开运行状况。如果您希望始终公开完整的健康信息,可以将
endpoints.health.sensitive
设置为false
。
答案 1 :(得分:0)
management.security.enabled =假
management.endpoints.web.exposure.include = *
我有类似的问题,并设置上述属性解决了它。
更新:我在1.5.9版本遇到此问题。使用最新版本2.0.2,它没有这些属性。事实上,“management.security.enabled”已在2.0.2中弃用。