2014-11-03 63 views
0

我試圖使用spring-data-cassandra(1.2.0.BUILD-SNAPSHOT)創建獨立的應用程序。 當嘗試使用下面的異常被拋出 (我的context.xml是here在設置bean屬性'cassandraTemplate'時無法解析對bean'cqlTemplate'的引用'

讚賞我做錯了其中任何提示「新的ClassPathXmlApplicationContext(‘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 
 
\t at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336) 
 
\t at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1457) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1198) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) 
 
\t at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
 
\t at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:687) 
 
\t at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) 
 
\t at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
 
\t at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
 
\t at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
 
\t at com.nosql.MainApp.search(MainApp.java:20) 
 
\t at com.nosql.MainApp.main(MainApp.java:26) 
 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cqlTemplate' is defined 
 
\t at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280) 
 
\t at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
 
\t at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 
 
\t ... 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: - 從來沒有使用過春天。

回答

0

據我所知,Spring無法找到名爲bean的cqlTemplate。 你必須在你的春天的背景下創造同樣的東西。 您可以按照下面的XML配置鏈接進行操作(第4.3.2節)。 http://docs.spring.io/spring-data/cassandra/docs/1.0.1.RELEASE/reference/html/cassandra.core.html

+0

是這個問題解決了,我面臨着類似的問題在我的獨立應用程序,其中應用程序啓動它失敗了同樣的錯誤。我正在嘗試使用Cassandra存儲庫中的Spring Data。 – 2015-03-24 18:43:42

+0

是的,創建了cqlTemplate bean,如下所示:http://docs.spring.io/spring-data/cassandra/docs/1.0.1.RELEASE/reference/html/cassandra.core.html#cassandra-connectors.xmlconfig – dwingle 2015-12-19 07:46:55

0

我使用的配置從there(實施例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" /> 

,並得到了同樣的錯誤,直到我經由主應用程序類註釋@EnableCassandraRepositories啓用卡桑德拉庫。它是這樣的:

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