我正在使用Spring Boot和Ignite数据库
我仅创建了一个存储库,并且正在Pojo中设置数据以使用IgniteRepository保存
以下是Ignite与Spring的必需依赖项: Ignite版本:: 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);
}
}
用户存储库界面:
@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
}
运行后出现错误:
线程“主”中的异常 org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为'userRepository'的bean时出错:不满意的依赖关系 通过构造函数参数0表示;嵌套异常为 org.springframework.beans.factory.NoSuchBeanDefinitionException:否 类型的合格豆 'java.lang.Class>'可用:至少有1个可以自动装配的bean 候选人。依赖项注释:{},位于 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:否 类型的合格豆 'java.lang.Class>'可用:至少有1个可以自动装配的bean 候选人。依赖项注释:{},位于 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个
答案 0 :(得分:0)
@RepositoryConfig
未声明@Repository或@Component。猜猜它没有被组件扫描。试试:
@Component
@RepositoryConfig(cacheName = "UserCacheConfig")
public interface UserRepository extends IgniteRepository<User, Long>{
User findByEmail(String email);
}