인터페이스 org.springframework.data.domain의 기본 또는 기본 생성자를 찾을 수 없습니다.페이지 가능
RestController에서 Pageable을 구현하려고 했는데 "No primary or default constructor found for interface org.springframework.data.domain"이라는 오류 메시지가 나타납니다.페이지 가능"
내 컨트롤러는
@GetMapping("/rest/category/all/page")
public Page<ItemCategory> getAllItemCategoryByPage(Pageable pageable){
Page<ItemCategory> categories = itemCategoryService.getAllItemCategoriesByPageable(pageable);
return categories;
}
내가 여기서 뭘 잘못하고 있는 거지?Spring Boot 2.0 어플리케이션입니다.잘 부탁드립니다!
선택한 솔루션은 회피책입니다.다음 구성을 사용하여 스프링에서 파라미터를 자동으로 해결하도록 할 수 있습니다.
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
@EnableSpringDataWebSupport
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add( new PageableHandlerMethodArgumentResolver());
}
}
WebFlux 앱에서도 같은 문제가 있었습니다.Spring Boot 2.4.0이 대응하는 것을 놓쳤다.@EnableSpringDataWebSupport
대응형 앱에 대응하고 있습니다만, 다행히, 기능하는 리졸바 실장을 제공하고 있습니다.다음의 방법으로 유효하게 할 수 있습니다.
@Configuration
public class PageableWebFluxConfiguration implements WebFluxConfigurer {
@Override
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
configurer.addCustomResolver(new ReactivePageableHandlerMethodArgumentResolver());
}
}
Clément Poissonnier의 솔루션을 사용하는 경우 구성 클래스가 다른 클래스를 재정의하지 않는지 확인합니다.
같은 문제가 발생했지만 다음 솔루션으로는 해결할 수 없었습니다.
@Configuration
@EnableSpringDataWebSupport
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add( new PageableHandlerMethodArgumentResolver());
}
}
난 여전히 메시지를 가지고 있었다:
인터페이스 org.springframework.data.domain의 기본 또는 기본 생성자를 찾을 수 없습니다.페이지 가능
그리고 이 프로젝트에 Swagger 설정 클래스가 있다는 것을 깨달았습니다.
@Configuration
@EnableSwagger2
public class SwaggerConfiguration extends WebMvcConfigurationSupport {
// Swagger configuration...
}
위의 WebMvcConfig 설정이 무시되었습니다.
솔루션은 다음 구성 클래스를 1개만 갖는 것이었습니다.
@Configuration
@EnableSwagger2
public class WebMvcConfig extends WebMvcConfigurationSupport {
// Swagger configuration...
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add( new PageableHandlerMethodArgumentResolver());
}
}
}
또한 John Paul Moore의 답변에 따라 @Enable Spring Data Web Support가 필요하지 않을 수도 있습니다.
테스트는 다음과 같이 설정할 수 있습니다.
@BeforeEach
public void setup(){
mockMvc = MockMvcBuilders.standaloneSetup(messageController)
.setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
.build();
}
자세한 것은, https://www.javafixing.com/2021/12/fixed-request-is-not-being-executed-in.html 를 참조해 주세요.
컨트롤러의 리팩터링을 제안합니다.
public List<ItemCategory> getAllItemCategoryByPage(@RequestParam("page") int pageIndex,
@RequestParam("size") int pageSize){
return itemCategoryService
.getAllItemCategoriesByPageable(PageRequest.of(pageIndex, pageSize)).getContent();
}
Pageable 앞에 주석이 없는 것 같습니다(클라이언트로부터의 데이터 송신은 어떻게 하고 있습니까?).
주석을 사용하여 @EnableSpringDataWebSupport를 활성화하는 것과 관련하여 이미 제공된 답변을 추가합니다.이것은, 스프링 부트 자동 설정으로 이미 유효하게 되어 있을 필요가 있습니다.설정을 확인해야 할 수도 있습니다.또는 이 자동 설정 클래스는 Java config 또는 응용 프로그램 속성에서 제외됩니까?
org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration
스프링 이외의 부트 코드의 경우:
스프링 부츠 없이 기존의 스프링 MVC 코드 베이스에 대응하고 있었습니다만, 이미,RequestMappingHandlerAdapter
xmls에 등록된 콩이라 어쩔 수 없이 이렇게 했어요.
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
...
<property name="customArgumentResolvers">
<list>
<bean class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
</bean>
</list>
</property>
</bean>
언급URL : https://stackoverflow.com/questions/52355490/no-primary-or-default-constructor-found-for-interface-org-springframework-data-d
'programing' 카테고리의 다른 글
jest + 효소, mount(), document.getElementById()를 사용하여 _method 호출 뒤에 표시되는 컴포넌트에서 null을 반환합니다. (0) | 2023.03.16 |
---|---|
angular UI 라우터| $stateParams가 동작하지 않음 (0) | 2023.03.16 |
그 이외의 경우 StateProvider에서 (0) | 2023.03.16 |
입력이 비어 있을 때 버튼을 비활성화하려면 어떻게 해야 합니까? (0) | 2023.03.16 |
여러 Atribute를 Angular.js Atribute Directive로 전달하려면 어떻게 해야 하나요? (0) | 2023.03.16 |