Spring Cloud Contract 404 On /Actuator /HealthJava

Java-Forum
Anonymous
 Spring Cloud Contract 404 On /Actuator /Health

Post by Anonymous »

Ich möchte einen Vertragstest mit Spring Cloud -Vertrag erstellen. /p>
Um dies zu tun, habe ich den folgenden Code geschrieben: < /p>
@SpringBootApplication
public class VideogameRecommendationServiceProducerApplication {

public static void main(String[] args) {
SpringApplication.run(VideogameRecommendationServiceProducerApplication.class, args);
}

}
< /code>
@RestController
public class RecommendationController {

@PutMapping("/question")
public ResponseEntity fetchRecommendations() {
return ResponseEntity.ok("OK");
}

}
< /code>

management.endpoints.web.exposure.include=*

< /code>
With the pom:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

org.springframework.boot
spring-boot-starter-parent
3.4.2


com.dreamseeker
videogame-recommendation-service
0.0.1-SNAPSHOT
videogame-recommendation-service-producer
Service destined to give tailor made videogame recommendations to users

23



org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-actuator



org.springframework.boot
spring-boot-starter-test
test


org.springframework.cloud
spring-cloud-starter-contract-verifier
4.2.0
test







org.springframework.cloud
spring-cloud-contract-maven-plugin
4.2.0
true

JUNIT5
com.dreamseeker.videogamerecommendationservice.BaseTestClass



org.springframework.boot
spring-boot-maven-plugin






< /code>
And finally, the important contract test class:
package com.dreamseeker.videogamerecommendationservice;

import com.dreamseeker.videogamerecommendationservice.controllers.RecommendationController;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.MOCK,
properties = {
"management.endpoints.web.exposure.include=*"
})
public class BaseTestClass {
@BeforeEach
void setUp() {
RestAssuredMockMvc.standaloneSetup(new RecommendationController());
}
}

< /code>
Contract:
request:
method: GET
url: /actuator/health
headers:
Content-Type: application/json
response:
status: 200
< /code>
I was hoping this test would pass with the 200 result.
Spinning up the server manually (not contract test) and just using curl to test the actuator health endpoint would work fine.
However, using the contract, I am facing this issue:
2025-02-12T18:39:45.159+08:00 INFO 3819 --- [ main] c.d.v.ContractVerifierTest : No active profile set, falling back to 1 default profile: "default"
2025-02-12T18:39:45.780+08:00 INFO 3819 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 14 endpoints beneath base path '/actuator'
2025-02-12T18:39:45.805+08:00 INFO 3819 --- [ main] c.d.v.ContractVerifierTest : Started ContractVerifierTest in 0.732 seconds (process running for 1.09)
Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build what is described in Mockito's documentation: https://javadoc.io/doc/org.mockito/mock ... o.html#0.3
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: A Java agent has been loaded dynamically (/Users/me/.m2/repository/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
2025-02-12T18:39:46.235+08:00 INFO 3819 --- [ main] o.s.mock.web.MockServletContext : Initializing Spring TestDispatcherServlet ''
2025-02-12T18:39:46.235+08:00 INFO 3819 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Initializing Servlet ''
2025-02-12T18:39:46.235+08:00 INFO 3819 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Completed initialization in 0 ms
2025-02-12T18:39:46.256+08:00 WARN 3819 --- [ main] o.s.web.servlet.PageNotFound : No mapping for GET /actuator
2025-02-12T18:39:46.258+08:00 WARN 3819 --- [ main] o.s.web.servlet.PageNotFound : No endpoint GET /actuator.
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.373 s

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post