2016-08-13 56 views
0

我正在構建一個使用Spring啓動和neo4j ogm的應用程序。春季啓動應用程序,neo4j LoadOneDelegate null - 運行春季啓動+ IDE不是瓶子

當我從彈簧工具套件或從gradle啓動運行時,它工作正常。但是,將它打包成jar之後,我得到這個錯誤。

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的元數據,這似乎是空:

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:[email protected]: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這個編譯:

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' 
    } 

注意我是個使用自定義的春天社會類的聯繫,正在導入在最後編譯 您的幫助將不勝感激:)

+0

我有同樣的問題,對此有何更新? – camposer

回答

0

找到解決方案。我不是出口到戰爭,而是出口了一個罐子。問題在於,將文件導出爲war會改變文件結構,這意味着無法正確完成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' 
}