Spring Boot, /actuator return Resource not found in Console

Viewed 238

Below mentioned are my pom.xml, application.yml and logs. All the /actuator & /actuator/* endpoints reverts back to a login page. Please find here the login page screenshot

There is a different application for tracking the admin. So admin dependencies are for that only.

Pom.xml :

<project>
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
        <relativePath/>
        <!-- lookup parent from repository -->
    </parent>
    <groupId>com.application.application-name</groupId>
    <artifactId>application-name</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>application-name</name>
    <description> service for handling the events</description>
    <packaging>jar</packaging>
    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.4.0</spring-boot-admin.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka-test</artifactId>
            <version>2.5.6.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.4.0</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Application-dev.yml:

security.basic.enabled: false

server:
  port: ${PORT:8087}
spring:
  application:
    name: XYZ
  boot:
    #   https://codecentric.github.io/spring-boot-admin/current/#spring-boot-admin-client
    admin:
      api-path: /instances
      client:
        auto-registration: true
        auto-deregistration: true
        register-once: true
        url: "http://localhost:9090"
        instance:
          name: XYZ
        username: superadmin
        password: admin
  security:
    filter:
      dispatcher-types: async,forward,request,error
    user:
      name: superadmin
      password: admin

logging:
  level:
#    root: ${ROOT_LOGGING_LEVEL:DEBUG}
    org:
      apache:
        kafka: ERROR
#      de:
#        codecentric:
#          boot:
#            admin:
#              client:
#                registration: DEBUG

management:
  endpoints:
    web:
      exposure:
        include: "*"
        exclude: heapdump
  endpoint:
    health:
      show-details: always
    metrics:
      enabled: true
    security:
      enabled: true
    shutdown:
      enabled: true
  health:
    mail:
      enabled: false
  server:
    port: 8087

Logs:

2022-04-12 17:21:52.701  INFO 568530 --- [nio-8087-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-04-12 17:21:52.701  INFO 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-04-12 17:21:52.701 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2022-04-12 17:21:52.701 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Detected AcceptHeaderLocaleResolver
2022-04-12 17:21:52.701 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Detected FixedThemeResolver
2022-04-12 17:21:52.702 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@139c2be3
2022-04-12 17:21:52.702 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.support.SessionFlashMapManager@37badac
2022-04-12 17:21:52.702 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2022-04-12 17:21:52.702  INFO 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2022-04-12 17:21:52.716 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/actuator", parameters={}
2022-04-12 17:21:52.725 DEBUG 568530 --- [nio-8087-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2022-04-12 17:21:52.726 DEBUG 568530 --- [nio-8087-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2022-04-12 17:21:52.727 DEBUG 568530 --- [nio-8087-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2022-04-12 17:25:01.621 DEBUG 568530 --- [nio-8087-exec-8] o.s.web.servlet.DispatcherServlet        : GET "/actuator/health", parameters={}
2022-04-12 17:25:01.623 DEBUG 568530 --- [nio-8087-exec-8] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2022-04-12 17:25:01.625 DEBUG 568530 --- [nio-8087-exec-8] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2022-04-12 17:25:01.625 DEBUG 568530 --- [nio-8087-exec-8] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND

Also, This is my security config for the application:



import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {


    @Override

    public void configure(WebSecurity web) throws Exception {

        web.ignoring().antMatchers("/actuator/**");
    }


}

Have I forgotten something to add or I'm doing something wrong? Please help me out on this as it is really important for me to resolve.

1 Answers

By default, all actuator endpoints are secured. In the application-dev.yml file, you need to disable the security for actuator endpoints.

management:
   security:
      enabled: false

If problem still persists, try to expose the endpoints you need manually:

management:
    endpoints:
        web:
            exposure:
                include: [health,actuator,info]

A hude drawback of using yml files: indentation. Try to use application.properties file instead. More readable and unnecessary hassle free.

Related