springspring-bootspring-data-jpaspring-data-restquerydsl

Cannot instantiate Querydsl Predicate in Spring Data Rest


I don't see why Spring try to instantiate my Predicate by interface. What configuration is responsible for binding predicate from http parameters? I have exception:

No primary or single unique constructor found for interface com.querydsl.core.types.Predicate

Who knows or sees my problem? I spent a lot of time trying to debug this. Thanks in advance!

It is my controller:

@RepositoryRestController(path = "/samples")
@RequiredArgsConstructor
public class SamplesController {

    private final PageMapper pageMapper;

    private final SamplesRepository dao;

    @Secured("lab_sample_read")
    @GetMapping
    public PagedModel<Sample> samplesPage(
        SamplesFilter parameters,
        @QuerydslPredicate(root = Sample.class) Predicate predicate,
        Pageable pageable
    ) {
        Page<Sample> page = dao.findAll(parameters, predicate, pageMapper.zeroIndexed(pageable));
        return PagedModel.of(page.getContent(), pageMapper.metaOneIndexed(page));
    }

}

My properties:

mvc.servlet.path: /labs

My dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.4</version>
</parent>

<groupId>xxx</groupId>
<artifactId>labs-application</artifactId>
<name>Application</name>
<description>Labs Application Module</description>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <classifier>jakarta</classifier>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <classifier>jakarta</classifier>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>

    <!-- todo restore -->
    <!-- <dependency> -->
    <!--     <groupId>org.springdoc</groupId> -->
    <!--     <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> -->
    <!-- </dependency> -->
</dependencies>

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <addResources>true</addResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

My logs with bean conditions and logged all registered: https://pastebin.com/wgkHc7Xi


Solution

  • Ok it's problem with spring data rest it was worked on @RestController, but no with @ReositoryRestController. https://github.com/spring-projects/spring-data-rest/issues/1210