首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring boot应用程序,neo4j LoadOneDelegate null -运行spring boot +集成开发环境而不是jar

Spring boot应用程序,neo4j LoadOneDelegate null -运行spring boot +集成开发环境而不是jar
EN

Stack Overflow用户
提问于 2016-08-13 08:56:49
回答 1查看 141关注 0票数 0

我正在构建一个使用Spring boot和neo4j ogm的应用程序。

当我从spring工具套件或gradle boot run运行它时,它工作得很好。但是,在将其打包到jar之后,我得到了这个错误。

代码语言:javascript
复制
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中的元数据的,这似乎是空的:

代码语言:javascript
复制
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用户类未被读取:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
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'

}

代码语言:javascript
复制
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")

}

代码语言:javascript
复制
  task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
  }

注意:我是一个在类中使用自定义spring的社交链接,这是在最后一次编译中导入的,非常感谢您的帮助:)

EN

回答 1

Stack Overflow用户

发布于 2016-09-01 22:05:53

找到了一个解决方案。我只导出了一个jar,而不是导出到war。问题是,将文件导出为war会更改文件结构,这意味着ogm映射无法正确完成。我的新gradle版本看起来像这样:

代码语言:javascript
复制
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'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38928181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档