问题
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;
}}
Repository:
@RepositoryConfig(cacheName = "usersCache")
public interface UsersRepository extends IgniteRepository<UserEntity, Integer> {
UserEntity getByUsername(String username);
}
And the service:
@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
I have no save* functions declarations in my repository. Only getByUsername().
- How can I fix that error?
- How can I connect few ignite nodes and works with them like a single Database?
- I have existing PostgreSQL database. Can I use them with Ignite? (I'm looking at ignite JDBC drivers and found that no PostgreSQL driver exists, onlyMySQL, SQL Server, H2 etc supported. But there is plain JDBC Driver among them).
Context of question described here: Which distributed database I need to choose for medium data project
回答1:
1. How can I fix that error?
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 entitties used are not Jpa Entities.
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)})
Now all the IgniteRepository interfaces (that are annotated with @RepositoryConfig) will be excluded from Jpa configurations.
2. How can I connect few ignite nodes and works with them like a single Database?
Simple, you need to form a Ignite Cluster. There are two kinds of Ignite instance, one that run 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.
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.
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.
3. I have existing PostgreSQL database. Can I use them with Ignite? (I'm looking at ignite JDBC drivers and found that no PostgreSQL driver exists, onlyMySQL, SQL Server, H2 etc supported. But there is plain JDBC Driver among them).
There is an abstract class called CacheStoreAdapter
. You just have to create class that extends that adapter and give your own implementation.
It acts like a persistent store. You can use any technology.
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 to 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
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).
Hope it helps you!
来源:https://stackoverflow.com/questions/53534260/apache-ignite-2-7-igniterepository-with-jpa2-is-not-injected