I have got a Spring Boot Microservice with custom Spring Boot Acturators. When i run the Jar directly i can access all of my Acturators, when i run the same Jar inside a Docker-Image i get a 404 Error.
SecurityConfig:
@Configuration
public class ActuatorSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.requestMatcher(EndpointRequest.toAnyEndpoint())
.anonymous()
//.authorizeRequests()
//.anyRequest().authenticated()
.and()
.httpBasic();
}
}
Application.yaml:
spring:
profiles: actuator
management.endpoints:
web.exposure.include: "*"
health.show-details: always
This is like the "Boilerplate-Code" of my Acturators:
@Component
@RestControllerEndpoint(id = "acturatorName")
public class acturatorNameActurator {
@GetMapping(value = "/foo", produces = "application/json")
public String bar(){
return "{\"status\":\"started\"}";
}
...
}
None of my Custom Acturators that work when i just run the Jar run Inside docker? /actuator/info
Does work for example but /actuator/metrics
doesnt. What can i do to fix this? Ty in advanced
Is maybe my SecurityConfiguration wrong? Does Spring maybe block the Request because the Container is in another (Docker) Network? But then i would get something different then 404 right?
Spring is Bind on IP 0.0.0.0
Port 8080, i can access my REST-Endpoints normally
i forgot to change/add the actuator spring profile
The problem was inside my Dockerfile:
FROM openjdk:8-jdk-alpine
ADD target/app.jar /jar/
VOLUME /tmp
EXPOSE 8080
ENV SPRINGPROFILES=prod
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "-Dserver.port=8080", "-Dserver.address=0.0.0.0", "/jar/app.jar", "--spring.profiles.active=${SPRINGPROFILES}"]
after i changed the dockerfile to
FROM openjdk:8-jdk-alpine
ADD target/app.jar /jar/
VOLUME /tmp
EXPOSE 8080
ENV SPRINGPROFILES=prod
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=${SPRINGPROFILES}","-jar", "-Dserver.port=8080", "-Dserver.address=0.0.0.0", "/jar/app.jar"]
and adding the env variable to my docker-compose-file it worked
environment:
- "SPRINGPROFILES=prod,actuator"
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.