cancel
Showing results for 
Search instead for 
Did you mean: 

ComponentScan creates problem with reactive neo4j database repository

km_muzahid
Node

Hi, I am new in neo4j and I am tried a lot to enable reactive neo4j repository with @EnableReactiveNeo4jRepositories. but it generates error. I know this error happens because of interface can not create a bean unless implemented.
but neo4j manual describe that they have implemented CRUD operation and it will enable by @EnableReactiveNeo4jRepositories. So, please help me to solve this problem. I am sharing here all of those code. [ I am flowing MVC pattern]

application.properties

spring.data.neo4j.uri= bolt://localhost:7687
spring.data.neo4j.password= test
spring.data.neo4j.username= neo4j
@SpringBootApplication
@ComponentScan(value = [
    "com.km.muzahid.HandFood.Config",
    "com.km.muzahid.HandFood.Controller",
    "com.km.muzahid.HandFood.Service",
    "com.km.muzahid.HandFood.Repositories"
])
@PropertySource(value = ["classpath:application.properties"], ignoreResourceNotFound = true)
class HandFoodApplication {
    @Value("\${server.port:8081}")
    private val port = 8081

    @Profile("default")
    @Bean
    fun nettyHttpServer(context: ApplicationContext?): HttpServer {
        val handler = WebHttpHandlerBuilder.applicationContext(context!!).build()
        val adapter = ReactorHttpHandlerAdapter(handler)
        val httpServer = HttpServer.create().host("localhost").port(port)
        return httpServer.handle(adapter)
    }

    companion object {
        @Throws(Exception::class)
        @JvmStatic
        fun main(args: Array<String>) {
            AnnotationConfigApplicationContext(
                    HandFoodApplication::class.java).use { context -> context.getBean(HttpServer::class.java).bindNow().onDispose().block() }
        }
    }
}

@Configuration
@EnableTransactionManagement
@EnableReactiveNeo4jRepositories
class Neo4jConfig : AbstractReactiveNeo4jConfig() {

    @Bean
    override fun driver(): Driver {
        return GraphDatabase.driver("bolt://localhost:7687",AuthTokens.basic("neo4j","test"))
    }

}
@Node
data class Category(
        @GeneratedValue
        @Id
        val id: Int,
        var name : String
)

interface CategoryInf : ReactiveNeo4jRepository<Category, Int>

@Service
class service{
    @Autowired
    lateinit var categoryInf: CategoryInf
    fun getCategories(): Flux<Category> {
        return categoryInf.findAll()
    }
}
@Controller
class Example {
    @Autowired
    lateinit var service: service
 @GetMapping("/person", produces = [MediaType.TEXT_EVENT_STREAM_VALUE])
    @ResponseBody
    fun hello(model: Model): Flux<Category> {
       return service.getCategories()
    }
  }
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'example': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'service': Unsatisfied dependency expressed through field 'categoryInf'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.km.muzahid.HandFood.Repositories.Inf.CategoryInf' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:89)
	at com.km.muzahid.HandFood.Config.AppsStartUp.HandFoodApplication$Companion.main(HandFoodApplication.kt:51)
	at com.km.muzahid.HandFood.Config.AppsStartUp.HandFoodApplication.main(HandFoodApplication.kt)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'service': Unsatisfied dependency expressed through field 'categoryInf'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.km.muzahid.HandFood.Repositories.Inf.CategoryInf' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1306)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	... 15 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.km.muzahid.HandFood.Repositories.Inf.CategoryInf' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1716)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1272)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	... 28 more
1 REPLY 1

gerrit_meier
Neo4j
Neo4j

I posted a question on StackOverflow. Please avoid cross-posting to help us keeping an overview of the open questions on several channels.