我正在做一个spring数据项目,并试图将Ignite缓存与之集成。我已经使用PagingAndSortingRepository
@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);
}
和我添加了一个新的Repository IgniteRepository
@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: name clash: deleteAllById(java.lang. iterable) inorg.apache.ignite.springdata22.repository。IgniteRepository和deleteAllById (java.lang.Iterable)org.springframework.data.repository.CrudRepository有相同的擦除,但都不覆盖另一个
从错误看来,不知何故,由于两个存储库都在内部扩展CrudRepository,它导致了一个问题,我无法找出原因以及如何解决这个问题。请帮忙。
根据您的错误,UserCacheRepository
继承了IgniteRepository.deleteAllById(Iterable<K> ids)
和CrudRepository.deleteAllById(Iterable<? extends ID> ids)
,但Iterable<K>
和Iterable<? extends ID>
的擦除将是相同的(仅Iterable
),因此我们陷入了类有两个具有绝对相同签名的方法的情况,这导致了名称冲突错误。
这个错误的根本原因是IgniteRepository
最初是在CrudRepository
没有deleteAllById()
方法时编写的,同时CrudRepository
带有现代版本的spring-boot-start -data-jpa有这个方法。
您可以尝试使用旧版本的spring数据,如果可能的话,您的其余应用程序
你也可以尝试显式覆盖deleteAllById(Iterable Iterable)方法,但我不确定它是否有帮助。
最好的选择是更新Apache - Ignite -extensions来使用最新的spring数据,所以你可以为此在Apache Ignite项目中创建一个Jira票据。