[英]java.lang.AssertionError: Status expected:<200> but was:<404> Spring Boot Page Not found
CheckoutController结帐控制器
@Controller
@Profile("!test")
public class CheckoutController {
private MonetaryAmount total = Money.of(0, EURO);
private final UniqueInventory<UniqueInventoryItem> inventory;
private final Katalog catalogue;
private List<UniqueInventoryItem> history = new ArrayList();
@Autowired
public CheckoutController(UniqueInventory<UniqueInventoryItem> _inventory, Katalog _catalogue){
inventory = _inventory;
catalogue = _catalogue;
}
//! Get Mappings
//@GetMapping("/checkout")
@RequestMapping("/checkout")
@PreAuthorize("hasRole('WORKER')")
public String checkout(Model model){
model.addAttribute("total", this.total);
model.addAttribute("history", this.history);
model.addAttribute("controller", this);
return "checkout"; // thymleafe located in proper path, visible when logged in
}
}
TestingController测试控制器
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class CheckoutControllerTests {
@Autowired
MockMvc mockMvc;
@BeforeEach
public void pre() {
// code
}
@Test
public void checkout() throws Exception {
// TODO Error msg: status expected:<200> but was:<404>
mockMvc.perform(get("/checkout").with(user("paul").roles("WORKER")))
.andExpect(status().isOk());
}
}
Where it says "/checkout" above, I could put all other available routes which are accepted, but not this one and I do not know why.在上面写着“/checkout”的地方,我可以放上所有其他被接受的可用路线,但不是这个,我不知道为什么。 Again, it's visible to my once logged in running the project.同样,一旦登录运行该项目,我就可以看到它。
I tried using RequestMapping instead of GetMapping but that didnt work either.我尝试使用 RequestMapping 而不是 GetMapping,但这也不起作用。 I googled with no success, in most cases people did not actually point to the right html file but thats not the case here either.我用谷歌搜索没有成功,在大多数情况下,人们实际上并没有指向正确的 html 文件,但这里也不是这种情况。 I am lost at this point, asked my friends and colleagues with no success.我在这一点上迷失了,问我的朋友和同事没有成功。
If you have any clue what it could be, improper mvc setup, yadada, please let me know!如果您有任何线索可能是什么,不正确的 mvc 设置,yadada,请告诉我!
You have conflicting profiles.您有冲突的个人资料。 Your controller is annotated with @Profile("!test")
while your test is executing with @ActiveProfiles("test")
.您的 controller 使用@Profile("!test")
注释,而您的测试使用@ActiveProfiles("test")
执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.