A SpringBoot project with testing was working fine until I added @AutoConfigureRestDocs
. Then the testing starting running on port 8080 where before there was no port that was apparent.
So, when I used to have
mockMvc.perform(get("/employee/address/1")
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$._links.self.href", is("http://localhost/employee/address/1")))
and it worked now it is failing with the error
java.lang.AssertionError: JSON path "$._links.self.href"
Expected: is "http://localhost/employee/address/1"
but: was "http://localhost:8080/employee/address/1"
I've tried to change application.yml to add server.port: -1 and other things but I cannot control the port. I'm not even sure what to set it to though I suppose 80 would be correct.
If you check the API of AutoConfigureRestDocs ,you will see below description:
The default value of uriPort
is 8080 , so you need to change it explicitly
@AutoConfigureRestDocs(uriPort = "80")
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.