i have created maven project using spring-data-neo4j. have installed standalone neo4j server community edition 2.3.3. trying save vertex objects database , retrieve them check works fine. then, able open created db in standalone server better visualization. using dependencies:
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>4.2.5.release</version> </dependency> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-neo4j</artifactid> <version>4.0.0.release</version> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency>
the configuration class is:
@configuration @componentscan("neo4j.example") @enableautoconfiguration @enableneo4jrepositories("neo4j.example.repository") public class app extends neo4jconfiguration { public app() { system.setproperty("username", "neo4j"); system.setproperty("password", "root"); } @override public sessionfactory getsessionfactory() { return new sessionfactory("neo4j.example.model"); } @override @bean @scope(value = "session", proxymode = scopedproxymode.target_class) public session getsession() throws exception { return super.getsession(); } @override public neo4jserver neo4jserver() { return new remoteserver("http://localhost:7474"); } public static void main(string[] args) { springapplication.run(app.class, args); } }
my nodeentity looks like:
@nodeentity public class vertex { private string name; @graphid private long id; @relationship(type = "pairs_with", direction = "undirected") public set<vertex> teammates; public vertex() { } // getters, setters, equals, tostring }
the repository:
@repository public interface vertexrepository extends graphrepository<vertex> { vertex findbyname(string name); list<vertex> findbyteammatesname(string name); }
the service:
@service public class vertexserviceimpl implements vertexservice { @autowired private vertexrepository vertexrepository; @override @transactional public vertex create(vertex vertex) { return vertexrepository.save(vertex); } @override @transactional public iterable<vertex> findall() { return vertexrepository.findall(); } //.... }
then have controller 2 simple methods save vertex , query database.
@restcontroller @requestmapping("/api/") public class graphcontroller { @autowired vertexservice vertexservice; @requestmapping(value = "addvertex", method = requestmethod.get) public void add() { vertex v = new vertex(); v.setid(1l); v.setname("name"); vertex v2 = new vertex(); v2.setid(2l); v.workswith(v2); vertexservice.create(v); } @requestmapping(value = "all", method = requestmethod.get) public iterable<vertex> getall() { return vertexservice.findall(); } }
when save vertex db there no error. when call /all db empty. checked messages.log , there no exception...last lines being:
2016-03-26 14:25:15.716+0000 info [o.n.k.i.diagnosticsmanager] interface microsoft wi-fi direct virtual adapter-wfp 802.3 mac layer lightweight filter-0000: 2016-03-26 14:25:15.716+0000 info [o.n.k.i.diagnosticsmanager] --- initialized diagnostics end --- 2016-03-26 14:25:15.747+0000 info [o.n.k.i.diagnosticsmanager] --- stopping diagnostics start --- 2016-03-26 14:25:15.747+0000 info [o.n.k.i.diagnosticsmanager] --- stopping diagnostics end --- 2016-03-26 14:25:15.747+0000 info [o.n.k.i.f.graphdatabasefacade] shutdown started
any appreciated!
you mixing embedded , remote server?
you should data in remote server.
also must have disabled auth work in server, or have provide username (neo4j) , password config.
do not start embedded database on same directory server uses
Comments
Post a Comment