从Java EE连接到neo4j服务器时遇到问题。
我用:
- localhost服务器模式下的 neo4j 3.0.1
- Weblogic 12.1.3
- JEE 7
- neo4j-ogm-core 2.0.3
- neo4j-ogm-bolt-driver 2.0.3
My Maven依赖项:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>2.0.3</version>
</dependency>
我在资源中的ogm.properties / META-INF:
#Driver, required
driver=org.neo4j.ogm.drivers.bolt.driver.BoltDriver
#URI of the Neo4j database, required. If no port is specified, the default port 7687 is used. Otherwise, a port can be specified with bolt://neo4j:password@localhost:1234
URI=bolt://neo4j:xxxxxx@localhost
#Connection pool size (the maximum number of sessions per URL), optional, defaults to 50
connection.pool.size=150
#Encryption level (TLS), optional, defaults to REQUIRED. Valid values are NONE,REQUIRED
encryption.level=NONE
#Trust strategy, optional, not used if not specified. Valid values are TRUST_ON_FIRST_USE,TRUST_SIGNED_CERTIFICATES
trust.strategy=TRUST_ON_FIRST_USE
我使用EJB Singleton来定义Session Factory:
@Singleton
public class Neo4jSessionFactory {
private SessionFactory sessionFactory;
@PostConstruct
public void init() {
sessionFactory = new SessionFactory("com.toto.poc.ejb.data.access");
}
/**
* Get neo4j session
* @return the session
*/
public Session getNeo4jSession() {
return sessionFactory.openSession();
}
}
它位于“com.toto.poc.ejb.data.access”包中。
我有一个EJB来定义想要调用的业务方法:
@Stateless
public class TopologyBusiness {
private @EJB Neo4jSessionFactory neo4jSessionFactory;
public Iterable<Map<String, Object>> getApplication(String irt) {
String query = "MATCH (a:Application) WHERE a.irt = '" + irt + "' RETURN a";
Session session = neo4jSessionFactory.getNeo4jSession();
return session.query(query, Collections.emptyMap());
}
}
但是当我的客户端调用TopologyBusiness时,会调用Neo4jSessionFactory的init(PostConstruct)方法,并发生错误:
com.oracle.pitchfork.interfaces.LifecycleCallbackException: Failure to invoke public void com.toto.poc.ejb.data.access.Neo4jSessionFactory.init() on bean class class com.toto.poc.ejb.data.access.Neo4jSessionFactory_wi88u8_Impl with args: null
at com.oracle.pitchfork.inject.Jsr250Metadata.invokeLifecycleMethod(Jsr250Metadata.java:379)
at com.oracle.pitchfork.inject.Jsr250Metadata.invokeLifecycleMethods(Jsr250Metadata.java:352)
at com.oracle.pitchfork.intercept.InterceptionMetadata.invokeLifecycleMethods(InterceptionMetadata.java:399)
at weblogic.ejb.container.injection.EjbComponentCreatorImpl.invokePostConstruct(EjbComponentCreatorImpl.java:55)
at weblogic.ejb.container.manager.SingletonSessionManager.constructAndInitBean(SingletonSessionManager.java:330)
Truncated. see log file for complete stacktrace
Caused By: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.oracle.pitchfork.inject.Jsr250Metadata.invokeLifecycleMethod(Jsr250Metadata.java:377)
Truncated. see log file for complete stacktrace
Caused By: java.lang.RuntimeException: org.neo4j.ogm.exception.ServiceNotFoundException: Resource: zip:C:/oracle/wls/12.1.3/user_projects/domains/CMDB/servers/LocalServer/tmp/_WL_user/poc-cdb-ear_ear/a8qjfi/poc-cdb-ejb-1.0-SNAPSHOT.jar!/com/toto.poc/ejb/data/access
at org.neo4j.ogm.ClassUtils.getUniqueClasspathElements(ClassUtils.java:178)
at org.neo4j.ogm.scanner.ClassPathScanner.getUniqueClasspathElements(ClassPathScanner.java:158)
at org.neo4j.ogm.scanner.ClassPathScanner.scan(ClassPathScanner.java:130)
at org.neo4j.ogm.metadata.DomainInfo.load(DomainInfo.java:316)
at org.neo4j.ogm.metadata.DomainInfo.<init>(DomainInfo.java:67)
Truncated. see log file for complete stacktrace
Caused By: org.neo4j.ogm.exception.ServiceNotFoundException: Resource: zip:C:/oracle/wls/12.1.3/user_projects/domains/CMDB/servers/LocalServer/tmp/_WL_user/poc-cdb-ear_ear/a8qjfi/poc-cdb-ejb-1.0-SNAPSHOT.jar!/com/toto.poc/ejb/data/access
at org.neo4j.ogm.service.ResourceService.resolve(ResourceService.java:53)
at org.neo4j.ogm.ClassUtils.getUniqueClasspathElements(ClassUtils.java:175)
at org.neo4j.ogm.scanner.ClassPathScanner.getUniqueClasspathElements(ClassPathScanner.java:158)
at org.neo4j.ogm.scanner.ClassPathScanner.scan(ClassPathScanner.java:130)
at org.neo4j.ogm.metadata.DomainInfo.load(DomainInfo.java:316)
Truncated. see log file for complete stacktrace
根本原因似乎是:
Caused By: org.neo4j.ogm.exception.ServiceNotFoundException: Resource: zip:C:/oracle/wls/12.1.3/user_projects/domains/CMDB/servers/LocalServer/tmp/_WL_user/poc-cdb-ear_ear/a8qjfi/poc-cdb-ejb-1.0-SNAPSHOT.jar!/com/toto.poc/ejb/data/access
我不知道为什么要在类路径中查看zip ... ... 谢谢你的帮助!
答案 0 :(得分:2)
我终于可以解决我的问题了,我浏览了奇怪的论坛,发现了一个在JBoss上有类似问题的人 所以我设法将此解决方案转换为Weblogic。
首先,您需要创建自己的资源解析器,以提供处理“zip”的方式。
覆盖ResourceResolver并实现如下解决方法:
com.toto.poc.core.access.ucmdb.Neo4jResourceResolver
然后在路径“ src / main / resources / META-INF / services ”中创建名为“ org.neo4j.ogm.classloader.ResourceResolver ”的文件。<登记/> 此文件只包含一行,即自定义ResourceResolver类的路径:
var app = angular.module('AngularApp', ['ngRoute', 'ngAnimate']);
app.config(function($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'menu.html',
controller: 'MenuController'
}).when('/slides/:menuItem', {
templateUrl: 'slides.html',
controller: 'SlidesController'
});
});
app.controller('MenuController', function($scope, $http) {
$http.get('database.json').then(function(response) {
$scope.bottomBar = 'no';
$scope.pageClass = 'menus';
$scope.database = response.data;
});
});
app.controller('SlidesController', function($scope, $http, $routeParams) {
$http.get('database.json').then(function(response) {
$scope.bottomBar = 'yes';
$scope.pageClass = 'slides';
$scope.database = _.find(response.data.menuItems, {'url': $routeParams.menuItem});
});
});
这很神奇,它有效!
Neo4j现在将探索jar存档,找到你的NodeEntities并将其映射到你的图表:)