I am trying to config embedded neo4j
with spring boot
. But after getting so much trouble with version of different package I came up with this
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>2.1.6</version>
<scope>compile</scope> <!--compatible with spring-boot-starter-data-neo4j 1.5.8.RELEASE-->
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.0</version>
<scope>runtime</scope>
</dependency>
This are the dependency of a graph module
which is a dependency of rest module
.
When I start the server everything go right but when I try to access neo4j server
with this code.
@Service
public class FileBasedImportServiceImpl implements ImportService {
private Session session;
@Autowired
public FileBasedImportServiceImpl(Session session) {
this.session = session;
}
@Transactional
public void clearDatabase() {
session.purgeDatabase();
}
@Transactional
public void load() {
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("school.cql")));
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append(" ");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
String cqlFile = sb.toString();
session.query(cqlFile, Collections.EMPTY_MAP);
}
}
by calling load()
method in a controller, I get connection refused.
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:7474 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
I think that the embedded neo4j
didn't start that's why. So how to make the embedded server start. I was thinking it will start automatically if I use spring boot but it wasn't the case.
Note: the file school.cql
contains cypher query
this is the project that I followed https://github.com/neo4j-examples/sdn-university
I have already add the annotation to my main class @EntityScan("com")
Thank you.
Update
This is the configuration annotation of spring application
@ComponentScan(basePackages={"com"})
@Configuration
@EnableJpaRepositories("com.repository")
@EntityScan(basePackages = {"com.domain", "org.springframework.data.jpa.convert.threeten"})
@EnableConfigurationProperties
@EnableAutoConfiguration
@EnableScheduling
@SpringBootApplication(exclude = org.activiti.spring.boot.SecurityAutoConfiguration.class)
@EnableNeo4jRepositories("com.graph.repository")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
Like I said I have followed this tutorial https://github.com/neo4j-examples/sdn-university and the only thing that I have done different is making two maven
module instead of one for the graph that contains the repository
/ domain entities
/service
related to neo4j
. The other module is related to spring boot
and to rest controller