Couchbase with Spring data using spring config example -
i newbie couchbase. using spring in application through trying connect couchbase in local. trying create couchbase template(similar done in mongo template) in configurations below:
repository using couchbase template
but when start application, autowiring errors , unable fetch anything. can please above issue? or if can share sample code extract data couchbase using sprin-data & spring configuration? please help!
so using spring data couchbase 1.4? framework offers dedicated namespace spring xml configuration should use instead of attempting call constructors:
xml configuration
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:couchbase="http://www.springframework.org/schema/data/couchbase" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/data/couchbase http://www.springframework.org/schema/data/couchbase/spring-couchbase.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <couchbase:couchbase host="127.0.0.1,192.168.1.101" bucket="default" password=""/> <couchbase:template/> <!-- use default client above, no additional tuning--> </beans> first notice xmlns:couchbase , couchbase-specific xsi:schemalocation in root.
secondly, not providing ids wire beans default ids (and same references, eg. default template reference default client if no "client-ref" attribute specified).
thirdly, notice format "host" parameter string, hostnames or ips separated commas (in case want bootstrap cluster).
at point template should available autowiring.
repository
for crud operations, spring data couchbase comes crudrepository abstraction. need to:
- declare interface
usersrepositoryextendingcrudrepository<users, string>(string being type ofusersfield identifying it). let's it's in packagecom.test.repo. - enable building of repositories framework in xml config:
<repositories base-package="com.test.repo" />(click relevant section of doc) - autowire repository:
@autowired public usersrepository repo;
the documentation has many more details concepts repositories, pre-requisites crud repository work in couchbase (short story: need create view up), how model , annotate entities, etc...
please have @ it, @ http://docs.spring.io/spring-data/couchbase/docs/1.4.0.release/reference/html/
Comments
Post a Comment