java.lang.AssertionError: Status expected:<200> but was:<404> Spring Boot Page Not found
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
}
}
测试控制器
@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());
}
}
上面写着“/checkout”的地方,我可以放置所有其他可用的路线,但这个路线不行,我不知道为什么。同样,我一旦登录 运行 项目就可以看到它。
我尝试使用 RequestMapping 而不是 GetMapping,但这也不起作用。我用谷歌搜索没有成功,在大多数情况下,人们实际上并没有指向正确的 html 文件,但这里也不是这种情况。此时我迷路了,问了我的朋友和同事没有成功。
如果您有任何线索可能是什么,不正确的 mvc 设置,yadada,请告诉我!
您的配置文件存在冲突。当您的测试使用 @ActiveProfiles("test")
.
执行时,您的控制器使用 @Profile("!test")
注释
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
}
}
测试控制器
@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());
}
}
上面写着“/checkout”的地方,我可以放置所有其他可用的路线,但这个路线不行,我不知道为什么。同样,我一旦登录 运行 项目就可以看到它。
我尝试使用 RequestMapping 而不是 GetMapping,但这也不起作用。我用谷歌搜索没有成功,在大多数情况下,人们实际上并没有指向正确的 html 文件,但这里也不是这种情况。此时我迷路了,问了我的朋友和同事没有成功。
如果您有任何线索可能是什么,不正确的 mvc 设置,yadada,请告诉我!
您的配置文件存在冲突。当您的测试使用 @ActiveProfiles("test")
.
@Profile("!test")
注释