简体   繁体   中英

Spring boot application actuator end points get registered and requests still fail

I have a Spring boot app with the following startup code. The Actuator end points get mapped and the beans get removed. I see the actuator end points registered and then the beans removed. Going by the SO thread , the messages are harmless. But when I try to reach any actuator end point, I am getting error. I am not sure what I should further look into to get actuators working. I am attaching all the log snippets that I was referring.

I have the project setup with maven:

Maven Spring Actuator section

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
    </dependency>

Java startup code

@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"));
}
}

The actuator starts the endpoints as per the log in DEBUG mode:

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'

Eventually I see in the logs that the beans are removed:

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

When I make a request to /info or /health to reach the info and health , I am directed to the whitelabel error page because there are no handlers found.

After debugging the dispatcher servlet I see that there are 7 handlers and I expected to find a mapping for the /info in 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 

Since the very first Mapping in the list is SimpleUrlHandlerMapping , it immediately returns "no handler mapping" which takes me to error page. I tried checking if the order matters and peeked into the BeanNameUrlHandlerMapping to see if it returns a handler mapping and it did not return any. So I suspect the debug message which removed the beans earlier is a culprit that caused the issue.

Can someone advise if there is anything I need to look into particularly.

According to the getting started guide : Building a RESTful Web Service with Spring Boot Actuator you should use the spring-boot-starter-actuator starter :

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

instead of the spring-boot-actuator dependency.

Note also that according to the Spring Boot reference :

Information returned by HealthIndicators is often somewhat sensitive in nature. For example, you probably don't want to publish details of your database server to the world. For this reason, by default, only the health status is exposed over an unauthenticated HTTP connection. If you are happy for complete health information to always be exposed you can set endpoints.health.sensitive to false .

management.security.enabled=false

management.endpoints.web.exposure.include=*

I had the similar issue and setting the above properties resolved it.

Update: I had this problem for version 1.5.9 . With the latest version 2.0.2, it works without these properties. In fact "management.security.enabled" has been deprecated in 2.0.2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM