gpt4 book ai didi

java - Querydsl maven编译报错: QClass.类不存在

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:05:04 26 4
gpt4 key购买 nike

我是 Querydsl 的新手,正在尝试在一个简单的测试项目中使用它。我按照官方教程配置我的 pom.xml,然后 mvn clean install 能够在 target/generated-sources/java 下生成 Q 类。但我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spring-jqgrid-tutorial: Compilation failure

[ERROR] /D:/Project/spring-jqgrid-tutorial/src/main/java/org/krams/controller/UserController.java:[92,62] package QUser.user does not exist

我认为根本原因是生成的Q类源文件没有自动编译成二进制类文件。我确实验证了我的项目目录下没有 QUser.class。我还尝试使用 build-helper-maven-plugin 添加 target/generated-sources/java 作为源文件夹,并在 apt-maven-plugin 配置中指定 target/generated-sources/java 作为附加源根。但我没有运气。

这是我的 pom.xml

<properties>
<querydsl.version>3.3.2</querydsl.version>
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.apt.plugin.version>1.1.1</maven.apt.plugin.version
<maven.build.helper.plugin.version>1.8</maven.build.helper.plugin.version>
<properties>

<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<scope>provided</scope>
</dependency>
<dependencies>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.build.helper.plugin.version}</version>
<executions>
<execution>
<id>add-source</id>
<phase>process-classes</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${maven.apt.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
<additionalSourceRoots>
<additionalSourceRoot>target/generated-sources/java</additionalSourceRoot>
</additionalSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugins>

这是生成的 QUser.java

package org.krams.domain;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.path.*;

import com.mysema.query.types.PathMetadata;
import javax.annotation.Generated;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PathInits;


/**
* QUser is a Querydsl query type for User
*/
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QUser extends EntityPathBase<User> {

private static final long serialVersionUID = -1712499619L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QUser user = new QUser("user");

public final NumberPath<Integer> age = createNumber("age", Integer.class);

public final StringPath firstName = createString("firstName");

public final NumberPath<Long> id = createNumber("id", Long.class);

public final StringPath lastName = createString("lastName");

public final StringPath password = createString("password");

public final QRole role;

public final StringPath username = createString("username");

public QUser(String variable) {
this(User.class, forVariable(variable), INITS);
}

public QUser(Path<? extends User> path) {
this(path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
}

public QUser(PathMetadata<?> metadata) {
this(metadata, metadata.isRoot() ? INITS : PathInits.DEFAULT);
}

public QUser(PathMetadata<?> metadata, PathInits inits) {
this(User.class, metadata, inits);
}

public QUser(Class<? extends User> type, PathMetadata<?> metadata, PathInits inits) {
super(type, metadata, inits);
this.role = inits.isInitialized("role") ? new QRole(forProperty("role"), inits.get("role")) : null;
}

}

下面是 UserController.java 中对 QUser 的唯一引用。 repository 是 UserRepository 存储库的一个实例,它扩展了 QueryDslPredicateExecutor。

package org.krams.controller;

import java.util.List;

import org.krams.domain.QUser;
import org.krams.domain.Role;
import org.krams.domain.User;
import org.krams.repository.UserRepository;
import org.krams.response.JqgridResponse;
import org.krams.response.StatusResponse;
import org.krams.response.UserDto;
import org.krams.service.UserService;
import org.krams.util.JqgridFilter;
import org.krams.util.JqgridObjectMapper;
import org.krams.util.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

...

if (qUsername != null)
users = repository.findAll(QUser.user.username.like(qUsername), pageRequest);

感谢您的帮助和评论。如果需要,我可以提供更多信息。

最佳答案

我再次从头开始构建所有内容,最后 Querydsl 开始工作了。我认为这个问题是由 spring data jpa 和 querydsl 的不兼容版本引起的。现在我正在使用 spring data jpa 1.3.2.RELEASE 和 querydsl 2.8.0.,一切正常。附言我删除了 additionalSourceRoots 和 build-helper-maven-plugin 配置。它们是不必要的。

关于java - Querydsl maven编译报错: QClass.类不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23040620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com