org.neo4j.ogm.exception.ResultProcessingException: 无法解析响应
org.neo4j.ogm.exception.ResultProcessingException: Could not parse response
我已经创建了一个新的 Maven 项目:
https://github.com/neosamples/neosamples
我逐渐复制内容的地方:
https://github.com/luanne/flavorwocky
更好地理解它是如何工作的以及需要哪些依赖项。现在我只想让单元测试将新项目添加到 GraphRepository 成为可能。目前我的项目有这样的布局:
其中:
Application.java
package com.samples.neo4j;
...(imports)
@Configuration
@ComponentScan("com.samples.neo4j")
@EnableAutoConfiguration
@EnableTransactionManagement
@EnableNeo4jRepositories("com.samples.neo4j.repository")
public class Application extends Neo4jConfiguration {
final String grapheneUrl;
public Application() {
grapheneUrl = "http://neo4j:neopass@localhost:7474";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(grapheneUrl);
return config;
}
@Override
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "com.samples.neo4j.domain");
}
@Override
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
}
其中neo4j是用户,neopass是我访问时使用的密码:
http://localhost:7474/browser/
并且:
我正在尝试 运行 这个单元测试:
@ContextConfiguration(classes = { PersistenceContext.class })
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class ServiceTest {
@Autowired
MyNodeRepository nodeRepository;
@Autowired
Session session;
@After
public void tearDown() {
session.purgeDatabase();
}
@Test
public void test() {
MyNode n = new MyNode("test");
nodeRepository.save(n);
MyNode node = IteratorUtil.firstOrNull(nodeRepository.findAll());
assertNotNull(node);
}
}
但是当我 运行 上面的单元测试时,我在控制台中收到以下错误:
2016-07-19 12:39:41,571 WARN o4j.ogm.drivers.http.request.HttpRequest: 235 - Caught response exception: Unauthorized
2016-07-19 12:39:41,596 WARN o4j.ogm.drivers.http.request.HttpRequest: 235 - Caught response exception: Auth scheme may not be null
和这个堆栈跟踪:
我已经尝试自定义我的 pom 依赖项很长一段时间了,但我觉得我在 运行 兜圈子,下面是我当前的配置:
有什么建议吗?
看来您的授权凭据不太正确。如果您采用了 flavorwocky 配置,则不清楚您的 GRAPHENEDB_URL 代表什么。也许修改您的代码以像这样直接配置 URI:
Application.java
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI("http://neo4j:password@localhost:7474");
(用你正在使用的任何东西替换 neo4j username/password/host/port)
编辑:
问题是这个依赖项与 SDN 4.1.2 使用的驱动程序不兼容:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-drivers</artifactId>
<version>2.0.0-M02</version>
<scope>test</scope>
</dependency>
您不需要包含对 HTTP 驱动程序的依赖。但是,如果您使用的是 Embedded 或 Bolt,则需要包括这些(已记录 here)
如果删除此依赖项,则不再存在身份验证问题,但您的测试仍会失败,因为 MyNode
无法实例化 - 它需要无参数构造函数。
对于单元测试,我建议遵循 flavorwocky 并使用嵌入式驱动程序。您需要包括 appropriate ogm.properties file.
我已经创建了一个新的 Maven 项目:
https://github.com/neosamples/neosamples
我逐渐复制内容的地方:
https://github.com/luanne/flavorwocky
更好地理解它是如何工作的以及需要哪些依赖项。现在我只想让单元测试将新项目添加到 GraphRepository 成为可能。目前我的项目有这样的布局:
其中:
Application.java
package com.samples.neo4j;
...(imports)
@Configuration
@ComponentScan("com.samples.neo4j")
@EnableAutoConfiguration
@EnableTransactionManagement
@EnableNeo4jRepositories("com.samples.neo4j.repository")
public class Application extends Neo4jConfiguration {
final String grapheneUrl;
public Application() {
grapheneUrl = "http://neo4j:neopass@localhost:7474";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(grapheneUrl);
return config;
}
@Override
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "com.samples.neo4j.domain");
}
@Override
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
}
其中neo4j是用户,neopass是我访问时使用的密码: http://localhost:7474/browser/
并且:
我正在尝试 运行 这个单元测试:
@ContextConfiguration(classes = { PersistenceContext.class })
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class ServiceTest {
@Autowired
MyNodeRepository nodeRepository;
@Autowired
Session session;
@After
public void tearDown() {
session.purgeDatabase();
}
@Test
public void test() {
MyNode n = new MyNode("test");
nodeRepository.save(n);
MyNode node = IteratorUtil.firstOrNull(nodeRepository.findAll());
assertNotNull(node);
}
}
但是当我 运行 上面的单元测试时,我在控制台中收到以下错误:
2016-07-19 12:39:41,571 WARN o4j.ogm.drivers.http.request.HttpRequest: 235 - Caught response exception: Unauthorized
2016-07-19 12:39:41,596 WARN o4j.ogm.drivers.http.request.HttpRequest: 235 - Caught response exception: Auth scheme may not be null
和这个堆栈跟踪:
我已经尝试自定义我的 pom 依赖项很长一段时间了,但我觉得我在 运行 兜圈子,下面是我当前的配置:
有什么建议吗?
看来您的授权凭据不太正确。如果您采用了 flavorwocky 配置,则不清楚您的 GRAPHENEDB_URL 代表什么。也许修改您的代码以像这样直接配置 URI:
Application.java
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI("http://neo4j:password@localhost:7474");
(用你正在使用的任何东西替换 neo4j username/password/host/port)
编辑:
问题是这个依赖项与 SDN 4.1.2 使用的驱动程序不兼容:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-drivers</artifactId>
<version>2.0.0-M02</version>
<scope>test</scope>
</dependency>
您不需要包含对 HTTP 驱动程序的依赖。但是,如果您使用的是 Embedded 或 Bolt,则需要包括这些(已记录 here)
如果删除此依赖项,则不再存在身份验证问题,但您的测试仍会失败,因为 MyNode
无法实例化 - 它需要无参数构造函数。
对于单元测试,我建议遵循 flavorwocky 并使用嵌入式驱动程序。您需要包括 appropriate ogm.properties file.