2016-08-13 83 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' 
}