java - 将 Spring 数据与 PagingAndSortingRepository 和 IgniteRepository 一起使用会引发错误
问题描述
我正在开发一个 spring 数据项目,并将 Ignite 缓存与其集成。我已经在使用 PagingAndSortingRepository<Entity, String>
@Repository public interface UserRepository extends PagingAndSortingRepository<User, String> {
Page<User> findByUserId(final String userId, final Pageable pageable);
Page<User> findByFirstName(final String firstName, final Pageable pageable);
Page<User> findByEmailAddress(final String emailAddress, final Pageable pageable);
Page<User> findAllBy(final Pageable pageable);
}
我添加了一个新的存储库 IgniteRepository<Entity, String>
@RepositoryConfig(cacheName = "UserCache")
public interface UserCacheRepository extends IgniteRepository<UserCacheDto, String> {
@Query("select UserCacheDto FROM UserCacheDto WHERE userId = ?")
List<UserCacheDto> findByUserId(final String userId);
@Query("select UserCacheDto FROM UserCacheDto WHERE firstName = ?")
List<UserCacheDto> findByFirstName(final String firstName);
@Query("select UserCacheDto FROM UserCacheDto WHERE emailAddress = ?")
List<UserCacheDto> findByEmailAddress(final String emailAddress);
}
此设置背后的想法是仅当缓存中未找到数据时才从数据库中获取
以下是我的项目依赖项
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.src.portal</groupId>
<artifactId>portalDataBaseCacheModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>portalDataBaseCacheModule</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring.version>2.5.4</spring.version>
<ignite.version>2.9.0</ignite.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring-data_2.2</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring-boot-autoconfigure-ext</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-zookeeper</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-log4j2</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-log4j</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>18.3.0.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
进行此集成后,我收到以下编译错误,
java:名称冲突:org.apache.ignite.springdata22.repository.IgniteRepository 中的 deleteAllById(java.lang.Iterable) 和 org.springframework.data.repository.CrudRepository 中的 deleteAllById(java.lang.Iterable<? extends ID>)相同的擦除,但两者都没有覆盖另一个
从错误看来,由于两个存储库都在内部扩展 CrudRepository 导致问题,我无法弄清楚为什么以及如何解决这个问题。请在这里帮忙。
解决方案
根据您的错误UserCacheRepository
继承 IgniteRepository.deleteAllById(Iterable<K> ids)
and CrudRepository.deleteAllById(Iterable<? extends ID> ids)
,但擦除Iterable<K>
andIterable<? extends ID>
将是相同的(只是Iterable
),因此当类具有两个签名完全相同的方法时,我们会遇到这种情况,这会导致名称冲突错误。
这个错误的根本原因是IgniteRepository
最初是在CrudRepository
没有deleteAllById()
方法时编写的,同时CrudRepository
现代版本的spring-boot-starter-data-jpa附带了这个方法。
如果您的应用程序的其余部分可能,您可以尝试将旧版本用于弹簧数据。
您也可以尝试显式覆盖 deleteAllById(Iterable iterable) 方法,但我不确定它是否有帮助。
最好的选择是更新 apache-ignite-extensions 以使用最新的 spring 数据,因此您可以为此在 Apache Ignite 项目中创建 Jira 票证。
推荐阅读
- sql - 如何在插入语句中使用每个月的动态表,而我们在一列中传递一个静态值
- qmap - 错误:没有适用于“bbox”的方法应用于“范围”类的对象
- sql - 如何从具有多个外键的多个表中删除行?
- ruby - 如何在 rspec 中测试私有助手(模块)方法
- zapier - 向 Zapier 注册应用程序
- pandas - 列包含第 3 列
- android - 如何在 Android MVP 项目中处理自定义 ArrayAdapter?
- javascript - 使用单一功能全屏制作多张图片
- elasticsearch - java.lang.instantiationerror org.elasticsearch.common.transport.transportaddress
- python - 如何仅在用户停止平移和缩放时同步范围?