- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有点被这个问题难住了。我见过的例子和我在网上找到的所有内容都表明这一点
public ResponseEntity<StandaloneTerminals> getTerminalsBySearchTerm(
@PathParam("term") String term, @PageableDefault(page = 0, size = 25) Pageable pageRequest) {
Page<StandaloneTerminal> terminals;
...
}
应该可以。当在单元测试中运行时
@RunWith(SpringRunner.class)
@WebMvcTest(TerminalController.class)
public class TerminalControllerTest {
...
@Test
public void getAll() throws Exception {
MvcResult result = this.mockMvc.perform(get("/terminals")).andDo(print())
.andExpect(status().is(200))
.andReturn();
...
}
确实如此!
但是,实际上将 Postman 指向该端点会导致
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface
我已经在 Stack Overflow 上阅读了有关此问题的多个问题,并尝试将 @EnableSpringDataWebSupport 添加到新的 WebConfig 类中,并在不同时间添加到我的 AppConfig 和 Controller 中,只是为了安全起见。 Spring 继续拒绝实例化此 bean。
编辑:根据要求编辑应用程序配置:
@SpringBootApplication
@EnableSpringDataWebSupport
public class AppConfig {
public static void main(String[] args) {
SpringApplication.run(AppConfig.class, args);
}
}
最佳答案
我们一直无法准确地弄清楚为什么 Spring 无法实例化这个 bean,但我们通过使用默认构造函数来实现我们自己的 Pageable 找到了一种非侵入性的解决方法。到目前为止,我们还没有运气让 Sort 以同样的方式工作。
关于java - 可分页实例化在 WebMvcTest 中成功,但在运行服务器上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52729389/
我正在我的应用程序中实现 JWT 身份验证。一切正常,但是当我运行已经存在的 @WebMvcTests 并检查返回的状态代码时,它们都失败并显示“实际:403”。 这是我当前的测试套件之一: @Web
我正在尝试使用 @WebMvcTest 创建 Controller 测试,据我了解,当我添加测试类的 @WebMvcTest(ClientController.class) 注释时它不应该创建大量的
在我将@Service 添加到 Controller 后,我的单元测试失败了。该项目是 Spring-boot v 2.0.1.RELEASE。我花了很多时间试图找到答案,但没有运气。该测试在我添加
我想在 BookRestController 中测试我的休息端点。我使用 @WebMvcTest 编写了一个测试。 @RunWith(SpringRunner.class) @WebMvcTest(B
我在 groovy 上有 Controller @RestController @RequestMapping('/v1') @CompileStatic class DatasourceResour
Spring Boot 1.4 添加了 @WebMvcTest,它连接了测试我的应用程序的 Web 切片所需的部分。这太棒了,但我也想确保我的自定义过滤器和安全代码已连接,这样我也可以验证它们是否正常
我要test application slices ,但有一个包我想排除,因为它与那些测试根本无关。 我正在尝试以这种方式排除包: @RunWith(SpringRunner.class) @WebM
我有一个 spring rest mvc Controller ,它的 url 是“/public/rest/vehicle/get”。在我的安全配置中,我定义了对/public/rest 的任何请求
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
使用@WebMvcTest 将通过查找@SpringBootConfiguration 类(例如@SpringBootApplication)自动配置所有web 层bean。 如果配置类在不同的包里,
我正在编写一个 Controller 测试,其中 Controller 看起来像 @RestController public class VehicleController { @Autow
我有一个 Spring Boot 应用程序,可生成大量 Controller ,我的目标是为特定 Controller 创建集成测试。我读到我们可以使用 @WebMvcTest 注释实现一个测试切片,
我有点被这个问题难住了。我见过的例子和我在网上找到的所有内容都表明这一点 public ResponseEntity getTerminalsBySearchTerm( @PathPa
我正在学习如何测试我的 SpringBoot 应用。 现在我正在尝试通过为现有工作项目创建测试来学习。 我从我的 AdminHomeController 开始,它在管理员登录时管理主页: @Con
我有以下主类。 @EnableJpaAuditing @SpringBootApplication @EnableJpaRepositories(repositoryFactoryBeanClass
我在测试 Spring Controller 时遇到了问题。我在我的测试类中使用注释@WebMvcTest。当我运行测试时,我得到这个错误:没有可用的“org.springframework.boot
是否有可能在测试上下文中声明一个 RestController ,最好是作为 Spring Boot 测试的内部类?我确实需要它用于特定的测试设置。我已经尝试以下简单示例作为 POC: import
我的目标是将之前使用 Spring Boot 1.3 开发的 Spring Boot 应用程序迁移到最新的 Spring Boot 版本 1.4。该应用程序由几个 maven 模块组成,其中只有一个包
我有一个 Controller 和一个使用 @WebMvcTest 的测试,它运行良好。现在我需要添加一些验证逻辑,为此我 @Autowired一个额外的 bean(一个 @Component ,一个
我有一个 Spring Boot 应用程序 (1.5.10.RELEASE),其中包含如下所示的主要 (SpringBootApplication): @SpringBootApplication @
我是一名优秀的程序员,十分优秀!