Cannot resolve reference to bean cassandraTemplate while setting bean property cassandraTemplate

我正在尝试使用spring data cassandra(1.2.0.BUILD-SNAPSHOT)创建一个独立的应用程序context.xml“”)引发以下异常(我的context.xml 是在这里context.xml

context.xml

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Cannot resolve reference to bean 'cqlTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cqlTemplate' is defined at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1457) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:687) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.nosql.MainApp.search(MainApp.java:20) at com.nosql.MainApp.main(MainApp.java:26) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cqlTemplate' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ... 16 more 2014-11-03 15:50:07,147 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#2e5d4162': [cassandraCluster]

context.xml

您必须在spring上下文中创建相同的。您必须在spring上下文中创建相同的。您必须在spring上下文中创建相同的。

<!-- Loads the properties into the Spring Context and uses them to fill in placeholders in the bean definitions --> <context:property-placeholder location="classpath:cassandra.properties" /> <!-- REQUIRED: The Cassandra Cluster --> <cassandra:cluster contact-points="${cassandra.contactpoints}" port="${cassandra.port}" /> <!-- REQUIRED: The Cassandra Session, built from the Cluster, and attaching to a keyspace --> <cassandra:session keyspace-name="${cassandra.keyspace}" /> <!-- REQUIRED: The Default Cassandra Mapping Context used by CassandraConverter --> <cassandra:mapping> <cassandra:user-type-resolver keyspace-name="${cassandra.keyspace}" /> </cassandra:mapping> <!-- REQUIRED: The Default Cassandra Converter used by CassandraTemplate --> <cassandra:converter /> <!-- REQUIRED: The Cassandra Template is the building block of all Spring Data Cassandra --> <cassandra:template id="cassandraTemplate" /> <!-- OPTIONAL: If you are using Spring Data for Apache Cassandra Repositories, add your base packages to scan here --> <cassandra:repositories base-package="org.spring.cassandra.example.repo" />

您必须在spring上下文中创建相同的。@EnableCassandraRepositories您必须在spring上下文中创建相同的。您可以按照下面的链接进行XML配置(第4.3.2节)。

@SpringBootApplication @ImportResource("classpath:app-integration.xml") @EnableCassandraRepositories public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }

I am trying to create a standalone application using spring-data-cassandra(1.2.0.BUILD-SNAPSHOT). When attempted to create the application context using 'new ClassPathXmlApplicationContext("context.xml")' the below exception is thrown (My context.xml is here)

Appreciate any hints on where I am doing wrong.

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Cannot resolve reference to bean 'cqlTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cqlTemplate' is defined at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1457) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:687) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.nosql.MainApp.search(MainApp.java:20) at com.nosql.MainApp.main(MainApp.java:26) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cqlTemplate' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ... 16 more 2014-11-03 15:50:07,147 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#2e5d4162': [cassandraCluster]

P.S:- never used spring before.

I used configuration from there (example 7):

<!-- Loads the properties into the Spring Context and uses them to fill in placeholders in the bean definitions --> <context:property-placeholder location="classpath:cassandra.properties" /> <!-- REQUIRED: The Cassandra Cluster --> <cassandra:cluster contact-points="${cassandra.contactpoints}" port="${cassandra.port}" /> <!-- REQUIRED: The Cassandra Session, built from the Cluster, and attaching to a keyspace --> <cassandra:session keyspace-name="${cassandra.keyspace}" /> <!-- REQUIRED: The Default Cassandra Mapping Context used by CassandraConverter --> <cassandra:mapping> <cassandra:user-type-resolver keyspace-name="${cassandra.keyspace}" /> </cassandra:mapping> <!-- REQUIRED: The Default Cassandra Converter used by CassandraTemplate --> <cassandra:converter /> <!-- REQUIRED: The Cassandra Template is the building block of all Spring Data Cassandra --> <cassandra:template id="cassandraTemplate" /> <!-- OPTIONAL: If you are using Spring Data for Apache Cassandra Repositories, add your base packages to scan here --> <cassandra:repositories base-package="org.spring.cassandra.example.repo" />

and got the same error till i enabled cassandra repositories via annotation @EnableCassandraRepositories in main application class. It's something like:

@SpringBootApplication @ImportResource("classpath:app-integration.xml") @EnableCassandraRepositories public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }

What is CassandraTemplate?

public class CassandraTemplate extends Object implements CassandraOperations, ApplicationEventPublisherAware, ApplicationContextAware. Primary implementation of CassandraOperations . It simplifies the use of Cassandra usage and helps to avoid common errors. It executes core Cassandra workflow.

What is CassandraRepository?

Cassandra-specific extension of the CrudRepository interface that allows the specification of a type for the identity of the @Table (or @Persistable ) type. Repositories based on CassandraRepository can define either a single primary key, use a primary key class or a compound primary key without a primary key class.

How does spring boot connect to Cassandra database?

Starting with Spring Initializr.
Choose either Gradle or Maven and the language you want to use. ... .
Click Dependencies and select Spring Data for Apache Cassandra..
Click Generate..
Download the resulting ZIP file, which is an archive of a web application that is configured with your choices..