春季数据JDBC+ querydsl:错误&quort jdbcrepositoryFactory不支持querydsl;
我想在QueryDSL支持下使用Spring Data JDBC。根据春季文档()它得到了支持,但我无法正常工作。
我将MariadB用作数据库,我的Springboot版本为2.6.0。
我在pom.xml中的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-sql-spring</artifactId>
</dependency>
配置:
@Configuration
@EnableJdbcRepositories
@EnableTransactionManagement
public class DBConfig {
}
我的实体类:
package com.test.model.metadata;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Table
public class Action {
@Id
private long id;
private String name;
...
}
我的存储库类:
package com.test.repository;
import java.util.List;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import com.test.model.Action;
import com.querydsl.core.types.Predicate;
@Repository
public interface ActionRepository extends PagingAndSortingRepository<Action, Long>, QuerydslPredicateExecutor<Action> {
@Override
List<Action> findAll(Predicate predicate);
}
querydsl谓词用法:
QAction action = QAction.action;
Predicate predicate = action.name.like("%Accept%");
List<Action> actions = actionRepository.findAll(predicate);
q类是由预处理程序正确生成的,汇编已遵循,但是在应用程序启动期间,我会遇到错误: org.springframework.data.repository.core.support.UnsupportedFragmentException: Repository com.atende.db.metadata.jdbcrepository.ActionRepository implements org.springframework.data.querydsl.QuerydslPredicateExecutor but JdbcRepositoryFactory does not support Querydsl!
我的解决方案可能会缺少什么?
当我直接与jdbctemplate一起使用queryDSL时,它也有效:
QAction action = QAction.action;
SQLTemplates dialect = new MySQLTemplates();
Connection connection = DataSourceUtils.getConnection(jdbcTemplate.getDataSource());
SQLQuery<String> query = new SQLQuery<>(connection, dialect);
List<Tuple> actions = query.select(action.id, action.name)
.from(action)
.where(action.name.like("%Action%"))
.fetch();
我还尝试使用infobip querydsl库(),但有同样的错误。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是对文档的误解(不是您的错,它是以不幸的方式结构的)。
您正在查看序言,描述了使用弹簧数据模块的一般方法。
这并不表明手头的模块(在这种情况下为JDBC)支持所有提到的功能。
This is a misinterpretation of the documentation (not your fault, it is structured in an unfortunate way).
You are looking at the preface which describes the general way to work with Spring Data modules.
This does not indicate that the module at hand (JDBC in this case) supports all the features mentioned.
春季数据JDBC不提供QueryDSL支持。
这意味着激活
@enablejdbcrepositories
spring-data-jdbc
存储库实现不提供queryDSL支持。如果您有
Infobip-spring-data-jdbc-QueryDSl-boot-starter
在classPath上,然后删除@enablejdbcrepositories
它应该有效。QUERYDSLJDBCPREDICATEEXECUTOR
是片段实现。Spring Data JDBC does not provide Querydsl support.
That means that the
@EnableJdbcRepositories
which activatesspring-data-jdbc
repository implementation does not provide Querydsl support.If you have
infobip-spring-data-jdbc-querydsl-boot-starter
on classpath and remove@EnableJdbcRepositories
it should work.QuerydslJdbcPredicateExecutor
is the fragment implementation.