【发布时间】:2019-07-05 19:00:55
【问题描述】:
我正在使用 Spring Boot 和 Ignite 数据库
我只创建了一个存储库,我正在 Pojo 中设置数据以使用 IgniteRepository 保存
以下是 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>
这里我使用的是 H2 数据库依赖项 如果我不使用它,我会收到另一个完全未知的错误。
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 接口:
@RepositoryConfig(cacheName = "UserCacheConfig")
public interface UserRepository extends IgniteRepository<User, Long>{
User findByEmail(String email);
}
现在主类::
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("george.paul01@xyz.com");
user.setId(1L);
user.setPassword("password");
userRepo.save(user);
User getUser=userRepo.findByEmail("george.paul01@xyz.com");
if(getUser!=null) {
System.out.println(getUser.getEmail());
System.out.println(getUser.getPassword());
}
else {
System.out.println("User name is not found");
}
}
用户 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
}
运行后出现错误:
线程“main”中的异常 org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名为“userRepository”的 bean 时出错:不满足的依赖关系 通过构造函数参数0表示;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 符合条件的 bean 类型 'java.lang.Class>' 可用:预计至少有 1 个符合自动装配条件的 bean 候选人。依赖注解:{} at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) 在 org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742) 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) 在 com.mphasis.springreact.services.admin.AdminController.main(AdminController.java:14) 造成的: org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 符合条件的 bean 类型 'java.lang.Class>' 可用:预计至少有 1 个符合自动装配条件的 bean 候选人。依赖注解:{} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) 在 org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) 在 org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ... 13 更多
【问题讨论】:
标签: spring-boot ignite