我正在构建一个使用Spring boot和neo4j ogm的应用程序。
当我从spring工具套件或gradle boot运行它时,它工作正常。但是,将它打包到罐子里后,我得到了这个错误。
java.lang.NullPointerException: null
at org.neo4j.ogm.session.delegates.LoadOneDelegate.lookup(LoadOneDelegate.java:56) ~[neo4j-ogm-core-2.0.4.jar!/:na]
at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:49) ~[neo4j-ogm-core-2.0.4.jar!/:na]
at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:142) ~[neo4j-ogm-core-2.0.4.jar!/:na]
at comds.service.GenericService.find(GenericService.java:32) ~[classes!/:na]
at comds.service.UserServiceImpl.find(UserServiceImpl.java:36) ~[classes!/:na]
at comds.service.UserServiceImpl.find(UserServiceImpl.java:25) ~[classes!/:na]
at comds.linkedIn.LinkedInSaveUser.saveUser(LinkedInSaveUser.java:84) ~[classes!/:na]
at comds.controller.LinkedInController.home(LinkedInController.java:64) ~[classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.7.RELEASE.jar!/:4.2.7.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.7.RELEASE.jar!/:4.2.7.RELEASE]
我怀疑这与ogm配置有关,因为包用于定义ogm中的元数据,这似乎是null:
package comds;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
public class Neo4jSessionFactory {
private final static String [] packages = {"comds.domain"};
private final static SessionFactory sessionFactory = new SessionFactory(getConfiguration(),packages);
private static Neo4jSessionFactory factory = new Neo4jSessionFactory();
public static Neo4jSessionFactory getInstance() {
return factory;
}
private Neo4jSessionFactory() {
}
private static Configuration getConfiguration() {
Configuration configuration = new Configuration();
configuration.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
.setURI("http://neo4j:test@localhost:7474");
return configuration;
}
public Session getNeo4jSession() {
return sessionFactory.openSession();
}
}
由于某种原因,未读取COMDS用户类:
@Service("userService")
public class UserServiceImpl extends GenericService<COMDSUser> implements UserService{
@Override
public Class<COMDSUser> getEntityType() {
return COMDSUser.class;
}
@Override
public COMDSUser find(Long id) {
COMDSUser user = super.find(id);
if(user != null){
return applyPrivacySettings(user);
}
return null;
}
//... more stuff
public class COMDSUser extends COMDSEntity{
public enum privacySettings{
SHOW_ALL, HIDE_PERSONAL_INFO,HIDE_ALL;
}
private String firstName;
private String lastName;
/// .. more stuff
package comds.domain;
import org.neo4j.ogm.annotation.GraphId;
public abstract class COMDSEntity {
@GraphId
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || id == null || getClass() != o.getClass()) return false;
COMDSEntity entity = (COMDSEntity) o;
if (!id.equals(entity.id)) return false;
return true;
}
@Override
public int hashCode() {
return (id == null) ? -1 : id.hashCode();
}
}
gradle build:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'COM_DS'
version = '0.1.0'
}
jar {
baseName = 'COM_DS'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
maven{ url "https://mvnrepository.com/artifact"}
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.3.6.RELEASE")
compile "io.springfox:springfox-swagger2:2.5.1-SNAPSHOT"
compile("io.springfox:springfox-swagger-ui:2.5.0")
compile 'org.neo4j.driver:neo4j-java-driver:1.0.1'
compile group: 'org.neo4j', name: 'neo4j', version: '3.0.3'
compile group: 'org.neo4j', name: 'neo4j-ogm-core', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-api', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-http-driver', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-bolt-driver', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-embedded-driver', version: '2.0.4'
compile group: 'com.voodoodyne.jackson.jsog', name: 'jackson-jsog', version: '1.1'
compile("org.hibernate:hibernate-validator")
compile("org.springframework.boot:spring-boot-starter-social-facebook")
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-test')
compile "org.springframework.social:spring-social-core:1.1.4.RELEASE"
compile("org.springframework.social:spring-social-security:1.1.4.RELEASE")
compile("org.springframework.social:spring-social-config:1.1.4.RELEASE")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile group: 'joda-time', name: 'joda-time', version: '2.9.4'
testCompile 'junit:junit:4.10'
compile group: 'org.springframework', name: 'spring-test', version: '4.3.2.RELEASE'
compile fileTree(dir: 'resources', include: ['*.jar'])
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
注意我是使用在类中链接的自定义spring社交,在最后一次编译中导入 非常感谢您的帮助:)
答案 0 :(得分:0)
找到解决方案。我只出口了一个罐子,而不是出口到战争。问题是将文件导出为战争会改变文件结构,这意味着无法正确完成ogm映射。我的新gradle构建如下:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'name'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
maven{ url "https://mvnrepository.com/artifact"}
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/'}
maven { url 'https://oss.sonatype.org/content/repositories/snapshots'}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.3.6.RELEASE")
compile "io.springfox:springfox-swagger2:2.5.1-SNAPSHOT"
compile("io.springfox:springfox-swagger-ui:2.5.0")
compile 'org.neo4j.driver:neo4j-java-driver:1.0.1'
compile group: 'org.neo4j', name: 'neo4j', version: '3.0.3'
compile group: 'org.neo4j', name: 'neo4j-ogm-core', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-api', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-http-driver', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-bolt-driver', version: '2.0.4'
compile group: 'org.neo4j', name: 'neo4j-ogm-embedded-driver', version: '2.0.4'
compile group: 'org.pac4j', name: 'spring-webmvc-pac4j', version: '1.1.1'
compile group: 'org.pac4j', name: 'pac4j-oauth', version: '1.9.2-SNAPSHOT'
compile group: 'org.pac4j', name: 'pac4j-core', version: '1.9.2-SNAPSHOT'
compile group: 'com.voodoodyne.jackson.jsog', name: 'jackson-jsog', version: '1.1'
compile("org.hibernate:hibernate-validator")
compile('org.springframework.boot:spring-boot-devtools')
compile group: 'javax.servlet.jsp.jstl', name: 'jstl', version: '1.2'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.5.4'
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-test')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile 'junit:junit:4.10'
compile group: 'org.springframework', name: 'spring-test', version: '4.3.2.RELEASE'
compile fileTree(dir: 'resources', include: ['*.jar'])
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}