Reputation: 399
I am using spring boot and Ignite Database
I have created only one Repository and I am setting data in Pojo to save using IgniteRepository
Here are the required dependency for Ignite with Spring: Ignite Version :: 2.0.0
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring-data</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.195</version>
</dependency>
Here I am using H2 database dependencies If I don't use it I receive another error which is completely unknown.
IgniteConfiguration :
@Configuration
@EnableIgniteRepositories(excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
TempRepository.class, GarageRepository.class, CarRepository.class,
IncidentRepository.class, MachineRepository.class, MileageRepository.class,
LicenseRepository.class})
})
public class IgniteSpringConfiguration {
@Bean
public Ignite igniteInstance() {
IgniteConfiguration cfg = new IgniteConfiguration();
// Setting some custom name for the node.
cfg.setIgniteInstanceName("eventInsights");
// Enabling peer-class loading feature.
cfg.setPeerClassLoadingEnabled(true);
// Defining and creating a new cache to be used by Ignite Spring Data
// repository.
CacheConfiguration<Long, User> userCacheConfig = new CacheConfiguration<Long, User>("UserCacheConfig");
// Setting SQL schema for the cache.
userCacheConfig.setIndexedTypes(Long.class, User.class);
cfg.setCacheConfiguration(new CacheConfiguration[] {
userCacheConfig,
});
return Ignition.start(cfg);
}
}
UserRepository Interface:
@RepositoryConfig(cacheName = "UserCacheConfig")
public interface UserRepository extends IgniteRepository<User, Long>{
User findByEmail(String email);
}
Now Main Class::
private static UserRepository userRepo;
private static AnnotationConfigApplicationContext ctx;
public static void main(String[] args) {
ctx = new AnnotationConfigApplicationContext();
ctx.register(IgniteSpringConfiguration.class);
ctx.refresh();
userRepo= ctx.getBean(UserRepository.class);
User user=new User();
user.setEmail("[email protected]");
user.setId(1L);
user.setPassword("password");
userRepo.save(user);
User getUser=userRepo.findByEmail("[email protected]");
if(getUser!=null) {
System.out.println(getUser.getEmail());
System.out.println(getUser.getPassword());
}
else {
System.out.println("User name is not found");
}
}
User Pojo:
public class User implements Serializable
{
private static final long serialVersionUID = 1L;
public Long id;
@QuerySqlField(index = true)
private String password;
@QuerySqlField(index = true)
private String email;
//getters and setters method here I am skipping in my question
}
After running I am getting error :
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userRepository': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.Class>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) at com.mphasis.springreact.services.admin.AdminController.main(AdminController.java:14) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.Class>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ... 13 more
Upvotes: 0
Views: 1328
Reputation: 1150
@RepositoryConfig
does not declare @Repository or @Component. Guess it doesn't get component scanned. Try:
@Component
@RepositoryConfig(cacheName = "UserCacheConfig")
public interface UserRepository extends IgniteRepository<User, Long>{
User findByEmail(String email);
}
Upvotes: 0