如何使它正常工作?
许多代码示例都说,如果我只添加@GraphId批注,它将得到修复,但是它不能解决任何问题,因此也已弃用。
我已经尝试完全删除成员“ id”,将可见性设置为“ package”和其他一些调整,但是没有缝成为我需要的解毒剂。
我稍稍编辑了代码,所以行号不匹配。组件中标有“ **”的线是我脸上的“爆炸”线。这就是对neo4j服务器的首次访问。
我已经在本地安装了neo4j服务器(社区),它还活着。
● neo4j.service - Neo4j Graph Database
Loaded: loaded (/lib/systemd/system/neo4j.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2018-07-03 22:29:35 CEST; 23h ago
Main PID: 30794 (java)
Tasks: 52 (limit: 4915)
CGroup: /system.slice/neo4j.service
└─30794 /usr/bin/java -cp /var/lib/neo4j/plugins:/etc/neo4j:/usr/share/neo4j/lib/*:/var/lib/neo4j/plugins/* -server -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -X
juli 04 20:47:28 serious01 neo4j[30794]: at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:143)
juli 04 20:47:28 serious01 neo4j[30794]: at org.neo4j.bolt.runtime.ExecutorBoltScheduler.executeBatch(ExecutorBoltScheduler.java:170)
juli 04 20:47:28 serious01 neo4j[30794]: at org.neo4j.bolt.runtime.ExecutorBoltScheduler.lambda$scheduleBatchOrHandleError$2(ExecutorBoltScheduler.java:153)
juli 04 20:47:28 serious01 neo4j[30794]: at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
juli 04 20:47:28 serious01 neo4j[30794]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
juli 04 20:47:28 serious01 neo4j[30794]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
juli 04 20:47:28 serious01 neo4j[30794]: at java.lang.Thread.run(Thread.java:748)
juli 04 21:05:56 serious01 neo4j[30794]: 2018-07-04 19:05:56.044+0000 WARN Illegal character 0x16 in state=START for buffer HeapByteBuffer@1fc3783f[p=1,l=218,c=8192,r=217]={\x16<<<\x03\x03\x00\xD5\x01\x00\x00\xD1\x03\x03[=\x1a\x93\x89u\xBf...\x03\x03\x01\x
juli 04 21:08:32 serious01 neo4j[30794]: 2018-07-04 19:08:32.787+0000 WARN Illegal character 0x16 in state=START for buffer HeapByteBuffer@1fc3783f[p=1,l=218,c=8192,r=217]={\x16<<<\x03\x03\x00\xD5\x01\x00\x00\xD1\x03\x03[=\x1b0\xCd\xF0\x14...\x03\x03\x01\x
juli 04 21:10:44 serious01 neo4j[30794]: 2018-07-04 19:10:44.330+0000 WARN Illegal character 0x16 in state=START for buffer HeapByteBuffer@1fc3783f[p=1,l=218,c=8192,r=217]={\x16<<<\x03\x03\x00\xD5\x01\x00\x00\xD1\x03\x03[=\x1b\xB4-\xF96...\x03\x03\x01\x03\
我的pom.xml(代码段):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
</dependencies>
Spring写入屏幕:
2018-07-04 21:10:42.686 WARN 11549 --- [ restartedMain] o.s.d.n.mapping.Neo4jPersistentProperty : No identity field found for class of type: org.tormodvaksvikhavaldsrud.app.initController when creating persistent property for : org.tormodvaksvikhavaldsrud.app.ActorRepository org.tormodvaksvikhavaldsrud.app.initController.actorRepository
我的域类:
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@NodeEntity
@Data
public class Actor {
@Id
@GeneratedValue
private Long id;
private String name;
}
我的存储库类:
import org.springframework.data.repository.CrudRepository;
public interface ActorRepository extends CrudRepository<Actor, Long> {
Actor findByName(String name);
}
我的组件类:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Component
public class initController implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger(initController.class);
@Autowired
ActorRepository actorRepository;
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("Your application started with option names : {}", args.getOptionNames());
**actorRepository.deleteAll();**
Actor testActor = makeActor("TestUser");
actorRepository.findAll().forEach((Actor a) -> a.toString());
}
private Actor makeActor(String name) {
Actor actor = new Actor();
actor.setName("TestUser");
actorRepository.save(actor);
System.out.println("Created:" + actor.toString());
return actor;
}
}
Spring的堆栈跟踪转储:
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:791) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:778) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.tormodvaksvikhavaldsrud.app.Application.main(Application.java:28) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.3.RELEASE.jar:2.0.3.RELEASE]
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open Neo4j Session for transaction; nested exception is org.neo4j.driver.internal.shaded.io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 485454502f312e3120343...
at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.doBegin(Neo4jTransactionManager.java:214) ~[spring-data-neo4j-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.0.8.RELEASE.jar:2.0.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at com.sun.proxy.$Proxy65.deleteAll(Unknown Source) ~[na:na]
at org.tormodvaksvikhavaldsrud.app.initController.run(initController.java:39) ~[classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:788) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
... 10 common frames omitted
Caused by: org.neo4j.driver.internal.shaded.io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 485454502f312e3120343...
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1106) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1162) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138) ~[neo4j-java-driver-1.5.0.jar:1.5.0-0f49eb425368377c0c3905e0769af9b70c88d65f]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
答案 0 :(得分:0)
我认为您启动了应用程序,然后调用了代码。
将您的班级更改为
@SpringBootApplication
public class MyInit {
private static final Logger logger = LoggerFactory.getLogger(initController.class);
@Autowired
ActorRepository actorRepository;
public static void main(String[] args) {
SpringApplication.run(MyInit.class, args);
}
@EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() {
logger.info("Your application started with option names : {}", args.getOptionNames());
**actorRepository.deleteAll();**
Actor testActor = makeActor("TestUser");
actorRepository.findAll().forEach((Actor a) -> a.toString());
}
private Actor makeActor(String name) {
Actor actor = new Actor();
actor.setName("TestUser");
actorRepository.save(actor);
System.out.println("Created:" + actor.toString());
return actor;
}
}