簡體   English   中英

找不到接口 org.springframework.data.jpa.domain.Specification] 的主要或默認構造函數,其根本原因

[英]No primary or default constructor found for interface org.springframework.data.jpa.domain.Specification] with root cause

我想實現 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()
                    );       
    }

彈簧庫:

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

我正在嘗試使用此框架來實現搜索功能: 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>()

你知道我該如何解決這個問題嗎? 當我使用部署到 JBoss 容器中的 Spring 時,我工作正常,但現在當我使用 Spring Standalone 應用程序時,我可以出現這個異常。

完整的錯誤日志: https : //pastebin.com/4j0sqTjr

根據規范, SpecificationArgumentResolver 應該添加到 argumentResolvers

@Configuration
@EnableJpaRepositories
public class MyConfig implements WebMvcConfigurer {

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

    ...
}
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import net.kaczmarzyk.spring.data.jpa.web.SpecificationArgumentResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;


@Configuration
@EnableJpaRepositories
public class MyConfig implements WebMvcConfigurer {

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM