java - Custom method in spring data couchbase -
i need write custom method spring data couchbase repository. here code.
cbsamplerepositorycustom.java
public interface cbsamplerepositorycustom { public void addindex() ; }
cbsamplerepositoryimpl.java
public class cbsamplerepositoryimpl implements cbsamplerepositorycustom { @override public void addindex() { system.out.println("cbsamplerepositorycustomimpl createindex"); } }
cbsamplerepository.java
@repository public interface cbsamplerepository extends couchbaserepository<content,string> , cbsamplerepositorycustom{ }
couchbasebeansconfiguration.java
@configuration public class couchbasebeansconfiguration { @bean public couchbaseclient couchbaseclient() throws ioexception { return new couchbaseclient(arrays.aslist(uri .create("http://localhost:8091/pools")), "test", ""); } @bean public couchbasetemplate couchbasetemplate() throws ioexception { return new couchbasetemplate(couchbaseclient()); } }
main.java
public static void main(string[] args) { applicationcontext context = new annotationconfigapplicationcontext( couchbasebeansconfiguration.class); couchbasetemplate template = context.getbean("couchbasetemplate", couchbasetemplate.class); repositoryfactorysupport factory = new couchbaserepositoryfactory( template); cbsamplerepository repository = factory.getrepository(cbsamplerepository.class); repository.addindex(); }
but while running showing error.
exception in thread "main" org.springframework.dao.invaliddataaccessresourceusageexception: not load view "addindex" design doc "content"; nested exception com.couchbase.client.protocol.views.invalidviewexception: not load view "addindex" design doc "content"
we need pass implementation class object getrepository function.change main class below.
main.java
public static void main(string[] args) { applicationcontext context = new annotationconfigapplicationcontext( couchbasebeansconfiguration.class); couchbasetemplate template = context.getbean("couchbasetemplate", couchbasetemplate.class); repositoryfactorysupport factory = new couchbaserepositoryfactory( template); cbsamplerepository repository = factory.getrepository(cbsamplerepository.class,new cbsamplerepositoryimpl()); cbsamplerepository repository = factory.getrepository(cbsamplerepository.class,custom); repository.addindex(); }
Comments
Post a Comment