Не найден основной или конструктор по умолчанию для интерфейса org.springframework.data.jpa.domain.Specification] с root причиной - PullRequest
0 голосов
/ 01 марта 2020

Я хочу реализовать приложение Spring, которое обслуживает таблицы со страницами:

[HPM] GET /api_admin/transactions/find?page=0&size=10

Контроллер:

@GetMapping("find")
    public Page<PaymentTransactionsDTO> getAllBySpecification(
            @And({
                    @Spec(path = "uniqueId", spec = LikeIgnoreCase.class),
                    @Spec(path = "createdAt", params = "from", spec = GreaterThanOrEqual.class, config="uuuu-MM-dd'T'HH:mm:ss.SSSX"),
                    @Spec(path = "createdAt", params = "to", spec = LessThanOrEqual.class, config="uuuu-MM-dd'T'HH:mm:ss.SSSX")
            }) Specification<Transactions> specification,
            @SortDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
    ) {        
        return transactionService.getAllBySpecification(specification, pageable)
                  .map(g -> TransactionsDTO.builder()                     
                            .id(g.getId()) 
                            ..............
                            .build()
                    );       
    }

Spring Repository:

public Page<PaymentTransactions> getAllBySpecification(final Specification<PaymentTransactions> specification, final Pageable pageable) {
        return this.dao.findAll(specification, pageable);
}

I'm пытаясь использовать эту платформу для реализации функции поиска: https://github.com/tkaczmarzyk/specification-arg-resolver

Я получаю сообщение об ошибке:

00:24:27.335 [http-nio-8020-exec-4] ERROR [dispatcherServlet][log:175] - Servlet.service() for servlet [dispatcherServlet] in context with path [/api_admin] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.data.jpa.domain.Specification] with root cause
java.lang.NoSuchMethodException: org.springframework.data.jpa.domain.Specification.<init>()

Знаете ли вы, как я могу исправить эту проблему ? Я работал нормально, когда использовал Spring, развернутый в контейнере JBoss, но теперь я могу сделать это исключение, когда использую Spring Standalone приложение.

Полный журнал ошибок: https://pastebin.com/4j0sqTjr

1 Ответ

1 голос
/ 01 марта 2020

В соответствии с значением c, SpecificationArgumentResolver должен быть добавлен к аргументу Resolvers

@Configuration
@EnableJpaRepositories
public class MyConfig implements WebMvcConfigurer {

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new SpecificationArgumentResolver());
    }

    ...
}
...