'Could not initialize class com.mysema.query.jpa.HQLTemplates

I've got a Spring boot application with a REST API and I'm trying to make the result-set filterable via the query parameters. Having looked at this article, I thought that QueryDSL would service this requirement quite well.

The problem I've got at the moment is that a class doesn't seem to be accessible at runtime... Moreover I've added the jar to classpath explicitly in IntelliJ

Error

java.lang.NoClassDefFoundError: Could not initialize class com.mysema.query.jpa.HQLTemplates
    at org.springframework.data.jpa.repository.support.Querydsl.createQuery(Querydsl.java:83) ~[spring-data-jpa-1.9.2.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.support.Querydsl.createQuery(Querydsl.java:98) ~[spring-data-jpa-1.9.2.RELEASE.jar:na]

the dependencies are in the pom and because I'm using the spring-boot-maven-plugin they should be bundled into the artifact.

POM

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</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>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>${querydsl.version}</version>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>${querydsl.version}</version>
    </dependency>

...

        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/apt</outputDirectory>
                        <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.mysema.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>${querydsl.version}</version>
                </dependency>
            </dependencies>
        </plugin>

Versions

<properties>
    <spring.boot.version>1.3.2.RELEASE</spring.boot.version>
    <querydsl.version>3.7.4</querydsl.version>
</properties>


Solution 1:[1]

This issue is fixed in below version `

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>5.0.0</version>
</dependency>

`

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sachin