我尝试升级我的测试以使用 TestContainers 和 Spring @DynamicPropertySource。
@Container
static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.0")
.withStartupTimeout(Duration.ofMinutes(5));
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("org.neo4j.driver.uri", neo4jContainer::getBoltUrl);
registry.add("org.neo4j.driver.authentication.username", () -> "neo4j");
registry.add("org.neo4j.driver.authentication.password", neo4jContainer::getAdminPassword);
}
Run Code Online (Sandbox Code Playgroud)
当我运行示例测试并得到以下异常时,测试开始时 Neo4j docker 似乎尚未准备好。
java.lang.IllegalStateException: Error processing condition on org.neo4j.driver.springframework.boot.autoconfigure.DriverConfiguration.neo4jDriver
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,使用MySQL和通过REST,Neo4j服务器版本执行一些批处理作业.
我无法弄清楚如何让它们正确地协同工作:我可以让它们同时工作,但不能同时工作.我发现的帖子并不是特定于Neo4j的服务器版本,也许这就是问题所在,因为其他一切对我来说都没问题.
我的配置:
JpaConfig
@Configuration
@EnableTransactionManagement(order=Ordered.HIGHEST_PRECEDENCE)
@PropertySource("META-INF/database.properties")
@ImportResource("classpath*:META-INF/repository.xml")
public class JpaConfig {
@Autowired
Environment env;
@Bean(destroyMethod = "close")
public DataSource dataSource() {
DataSource dataSource = new DataSource();
dataSource.setDriverClassName(env.getProperty("database.driverClassName"));
dataSource.setUrl(env.getProperty("database.url"));
dataSource.setUsername(env.getProperty("database.username"));
dataSource.setPassword(env.getProperty("database.password"));
dataSource.setTestOnBorrow(true);
dataSource.setTestOnReturn(true);
dataSource.setTestWhileIdle(true);
dataSource.setTimeBetweenEvictionRunsMillis(1800000);
dataSource.setNumTestsPerEvictionRun(3);
dataSource.setMinEvictableIdleTimeMillis(1800000);
dataSource.setValidationQuery("SELECT 1");
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setDataSource(dataSource());
entityManagerFactory.setPackagesToScan("it.smartblue.mcba.domain");
entityManagerFactory.setJpaDialect(new HibernateJpaDialect());
Map<String, String> jpaProperties = new HashMap<>();
jpaProperties.put("hibernate.connection.charSet", "UTF-8");
jpaProperties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.EJB3NamingStrategy");
jpaProperties.put("hibernate.bytecode.provider", "javassist");
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
entityManagerFactory.setJpaPropertyMap(jpaProperties);
entityManagerFactory.setPersistenceProvider(new HibernatePersistence());
return entityManagerFactory;
}
@Bean
public PlatformTransactionManager transactionManager() …Run Code Online (Sandbox Code Playgroud) 我们选择neo4j作为我们的Web应用程序的DB.用户具有大量关系和连接节点.截至目前,用户约有20个关系.其中一项功能是新闻源功能.如果我想完全删除用户,cypher查询是删除的最佳方式还是有其他选择?
由于我们仍计划添加新功能,因此与用户相关的关系和节点也将增加.因此,如果我们使用cypher查询,则必须针对添加的每个新关系修改查询.请指教.
谢谢,帕万
我知道使用Spring数据neo4j的高级映射而不是简单的映射有很多优点.
我的问题是在简单映射上使用高级映射的缺点是什么?
我在spring数据neo4j中通过GraphRepository的@Query注释使用了以下查询.因此,为了获得结果,我将方法的返回类型声明为List
@Query(value = "START user=node:searchByMemberID(memberID=1) MATCH user-[r:FRIENDS_WITH]->member RETURN member")
List<Node> getNodes(int userID);
Run Code Online (Sandbox Code Playgroud)
现在,如果我想编写一个返回2列的查询,那么它的相应方法的返回类型是什么.例如,对于下面提到的查询,我应该代替List写什么,如上面的查询.
START user=node:searchByMemberID(memberID='1') MATCH user-[r:FRIENDS_WITH]->member RETURN member, r.property
Run Code Online (Sandbox Code Playgroud) 我想用大量节点测试Neo4j性能.我正在考虑创建数十亿个节点,然后想要查看获取符合某些条件的节点所需的时间.就像10亿个标记为具有SSN属性的人一样
match (p:Person) where p.SSN=4255556656425 return p;
Run Code Online (Sandbox Code Playgroud)
但是,如何创建10亿个节点,有没有办法生成10亿个节点?
我想在某个类型节点之间定义一些关系类型.当我查看示例时,他们总是使用String来定义关系类型,如本例所示.通过使用:
@RelationshipEntity(type = "ACTED_IN")
Run Code Online (Sandbox Code Playgroud)
我试图使用org.neo4j.graphdb.RelationshipType但是RelationshipEntity.type期望一个字符串.
public enum PersonMovieRelationshipType implements RelationshipType {
ACTED_IN("ACTED_IN"),
AUTHOR("AUTHOR");
private String type;
PersonMovieRelationshipType( String type ){
this.type = type;
}
public String getType() {
return type;
}
}
Run Code Online (Sandbox Code Playgroud)
RelationshipType枚举提供了一个方法"name()"如何处理?
我不喜欢自由文本的方式,是否可以使用枚举?
任何完整的例子将不胜感激.
问候
我正在使用Embedded JavaAPI来实现我的实时应用程序.当一个事务被锁定数据库时,我的另一个ajax调用抛出数据库实例已被其他进程锁定的错误.大部分时间我的电话都是只读的.所以我的问题是:Neo4J JavaAPI中是否存在任何方法,以便我可以将事务锁定为只读,以便其他请求可以从DB获取数据.
dbFactory = new GraphDatabaseFactory();
db= dbFactory.newEmbeddedDatabase(DB_PATH);
tx = db.beginTx();Run Code Online (Sandbox Code Playgroud)
所以在这个db.beginTx()我可以告诉Neo4j它是一个只读模式或类似的东西.
谢谢,
在我的Neo4j/Spring Data Neo4j项目中,我有以下异常类:
public class CriterionNotFoundException extends NotFoundDomainException {
private static final long serialVersionUID = -2226285877530156902L;
public CriterionNotFoundException(String message) {
super(message);
}
}
Run Code Online (Sandbox Code Playgroud)
在应用程序启动期间,我看到以下WARN:
WARN o.s.d.n.m.Neo4jPersistentProperty - No identity field found for class of type: com.example.domain.dao.decision.exception.DecisionAlreadyExistsException when creating persistent property for field: null
Run Code Online (Sandbox Code Playgroud)
为什么Neo4j/SDN在这个类中寻找身份字段?如何正确配置我的应用程序以跳过此警告?
spring neo4j spring-data-neo4j spring-boot spring-data-neo4j-4
当我尝试使用spring代码创建关系时,我收到了事务管理器错误.我在我的项目中使用Mysql和Neo4j数据库.我尝试了不同的解决方案,但无法解决.
org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为'transactionManager'的bean可用:没有为限定符'transactionManager'找到匹配的PlatformTransactionManager bean - 既没有限定符匹配也没有bean名称匹配!
Pom.xml文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<!-- For Neo4J Graph Database -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.9-rc</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
Application.class
@SpringBootApplication
@EnableTransactionManagement
@EntityScan("projectone.entities")
public class Application {
public static void main(String[] args) {
//For Starting …Run Code Online (Sandbox Code Playgroud)