不会注入带有JPA2的Apache Ignite 2.7 IgniteRepository [英] Apache Ignite 2.7 IgniteRepository with JPA2 is not injected

查看:73
本文介绍了不会注入带有JPA2的Apache Ignite 2.7 IgniteRepository的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基于Web的行会创建带有Spring Data JPA 2应用程序的简单Spring Boot 2.Spring Boot JPA 2支持仅在2.7版本中添加到Apache Ignite(现在仅在每晚构建时才可用- Apache Ignite 2.7发行日期).有代码片段:配置:

Using guildes founded on the web, I make the simple Spring Boot 2 with Spring Data JPA 2 application. Spring Boot JPA 2 support added to Apache Ignite only with 2.7 version (now it's avatilble only by nightly builds - Apache Ignite 2.7 release date). There are code snippets: Configuration:

@Configuration
@EnableIgniteRepositories
public class SpringDataConfig {

    @Bean
    public Ignite igniteInstance() {
        IgniteConfiguration config = new IgniteConfiguration();

        config.setIgniteInstanceName("ignite-1");
        config.setPeerClassLoadingEnabled(true);

        CacheConfiguration cache = new CacheConfiguration("usersCache");
        cache.setIndexedTypes(Integer.class, UserEntity.class);

        config.setCacheConfiguration(cache);
        Ignite ignite = Ignition.start(config);
        ignite.cluster().active(true);
        return ignite;
    }}

存储库:

@RepositoryConfig(cacheName = "usersCache")
public interface UsersRepository extends IgniteRepository<UserEntity, Integer> {
    UserEntity getByUsername(String username);
}

服务:

@Service
public class UserServiceImpl implements UserService {
    @Autowired
//    UsersRepository repository;
    ApplicationContext context;

    @Override
    public UserEntity getByUsername(String username) {
        return context.getBean(UsersRepository.class).getByUsername(username);
    }}

在运行时,我有以下例外情况:

On run I have the following exception:

[09:59:18] Ignite node started OK (id=8497f64c, instance name=ignite-1)
[09:59:18] Topology snapshot [ver=1, locNode=8497f64c, servers=1, clients=0, state=ACTIVE, CPUs=4, offheap=1.5GB, heap=1.7GB]
..

Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.lang.Iterable org.apache.ignite.springdata20.repository.IgniteRepository.save(java.util.Map)! No property save found for type UserEntity!
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:82)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:208)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:565)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:558)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Iterator.forEachRemaining(Iterator.java:116)
    at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:560)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:550)
    at java.util.Optional.map(Optional.java:215)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:550)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:323)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$4(RepositoryFactoryBeanSupport.java:290)
    at org.springframework.data.util.Lazy.getNullable(Lazy.java:141)
    at org.springframework.data.util.Lazy.get(Lazy.java:63)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:293)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
    ... 67 more
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property save found for type UserEntity!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:334)
    at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:287)
    at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:269)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:252)
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:81)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:251)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:381)
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:93)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:76)
    ... 93 more

我的存储库中没有save *函数声明.仅getByUsername().

I have no save* functions declarations in my repository. Only getByUsername().

  1. 如何解决该错误?
  2. 如何连接几个点火节点并像单个数据库一样与他们一起工作?
  3. 我有现有的PostgreSQL数据库.我可以将它们与Ignite一起使用吗?(我正在查看ignite JDBC驱动程序,发现不存在PostgreSQL驱动程序,仅支持MySQL,SQL Server,H2等.但是有普通的JDBC驱动程序其中).

此处描述的问题上下文:哪个我需要为中等数据项目选择分布式数据库

Context of question described here: Which distributed database I need to choose for medium data project

推荐答案

  1. 如何解决该错误?

我有同样的问题.当我们尝试同时使用JPA信息库和Ignite信息库时,Spring会将Ignite信息库视为JPA信息库,因为它也是从Repository接口扩展而来的.它会尝试将我们的IgniteRepository作为JpaRepository实施,这会失败,因为所使用的实体不是Jpa实体.

I had the same issue. When we try to use JPA repositories and Ignite repositories together, Spring considers Ignite Repository as a JPA repository, as it also extends from the Repository interface. It tries to give implementation for our IgniteRepository as a JpaRepository, that will fail because entities used are not Jpa Entities.

因此,我们需要从JpaRepository配置中排除IgniteRepository接口.为此,您可以在 @SpringBootApplication注释下添加注释.

So we need to exclude IgniteRepository interfaces from JpaRepository configuration. For that, you can add the annotation below @SpringBootApplication annotation.

@EnableJpaRepositories(excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = RepositoryConfig.class)})

现在,所有IgniteRepository接口(用 @RepositoryConfig 注释)将从Jpa配置中排除.

Now all the IgniteRepository interfaces (that are annotated with @RepositoryConfig) will be excluded from Jpa configurations.

  1. 如何连接几个点火节点并像单个数据库一样使用它们?

简单,您需要形成一个Ignite群集.Ignite实例有两种,一种在一个实例中单独运行,另一种在另一个应用程序(例如Spring Boot App)中运行.就您而言,您正在尝试在Spring Boot应用程序中创建一个ignite实例.要回答您的问题,您需要配置DiscoverySpi和CommunicationSpi.

Simple, you need to form an Ignite Cluster. There are two kinds of Ignite instance, one that runs separately in an instance and another one that runs inside another application (like a Spring Boot App). In your case, you're trying to create a ignite instance within a Spring Boot Application. To answer your question, you need to configure DiscoverySpi and CommunicationSpi.

这意味着您必须配置要在其上运行Ignite实例的节点的IP和用于通信的端口.只需阅读文档即可.

That means you've to configure the IPs of nodes on which you want to run Ignite Instance and ports for communication. Just go through the documentation.

但是我将解释使用它的场景.我们开发了一个可在4个实例上运行的应用程序.因此,我们为Ignite配置了4个实例IP和端口号以进行通信.现在,假设一个实例启动,它将在其中创建一个点燃节点,而当另一个实例启动时,将在其中创建另一个点燃节点.现在,两个节点将在您指定的端口上相互通信.您可以将此群集用作分布式缓存.

But I'll explain the scenario where we used it. We developed an app that runs on 4 instances. So We configured Ignite with 4 instances IPs and port numbers for communication. Now let's say one instance is up, it will create one ignite node inside that, and when another instance is up, another ignite node will be created in that. Now two nodes will communicate with each other on the port you specified. You can use this cluster as a distributed cache.

  1. 我有现有的PostgreSQL数据库.我可以将它们与Ignite一起使用吗?(我正在查看ignite JDBC驱动程序,发现不存在PostgreSQL驱动程序,仅支持MySQL,SQL Server,H2等.但是其中有普通的JDBC驱动程序.)

有一个名为 CacheStoreAdapter 的抽象类.您只需要创建一个扩展该适配器并提供自己的实现的类即可.它充当持久性存储.您可以使用任何技术.

There is an abstract class called CacheStoreAdapter. You just have to create a class that extends that adapter and give your own implementation. It acts as a persistent store. You can use any technology.

您将数据存储在点火缓存中.点燃然后将它们存储在数据库中.实际上,它将调用CacheStoreAdapter的方法,仅此而已.无论您提供哪种实现,都将执行.它具有写方法.如果仅将其打印到控制台,就可以在控制台上打印数据.如果使用JPA将其存储在DB中,它将进行存储.您可以给出任何实现方式.它不依赖于驱动程序或任何东西,仅取决于您的CacheStoreAdapter实现

You store data in ignite cache. Ignite inturn store them in the DB. Actually it will call the methods of CacheStoreAdapter, that's it. Whatever implementation you give, that will be executed. It has a write method. If you just make it print data to console, that's it it will print on console. If you make it store in DB using JPA, it will store. You can give any implementation. It doesn't depend on drivers or anything, just your CacheStoreAdapter implementation

这里的问题是,您创建的适配器不是Spring托管的bean,因此您将无法直接注入Jpa Repo或任何spring bean,但是可以间接进行操作(使用Google).

The problem here is, the adapter you create is not a spring managed bean, so you will not be able to inject you Jpa Repo or any spring beans directly, but you can do indirectly (Google it).

希望它对您有帮助!

这篇关于不会注入带有JPA2的Apache Ignite 2.7 IgniteRepository的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆