gpt4 book ai didi

java - Spring ERR_CONNECTION_REFUSED

转载 作者:行者123 更新时间:2023-12-02 11:42:47 26 4
gpt4 key购买 nike

我正在学习有关 spring 的教程,到目前为止,我的代码允许您添加用户并查看所有用户。我现在正在尝试添加删除功能。我添加了以下代码来实现此目的。我相信它与教程中所示完全相同,但结果我得到 ERR_CONNECTION_REFUSED。在教程中,此错误最初显示,但刷新后消失,但在我的情况下它没有。

index.html

<a href="#" th:href="@{/user/delete/}+${user.id}">Delete</a>

userService.java

public void delete(User user) {userRepository.delete(user); }

用户 Controller .java

@RequestMapping(value = "/delete/{user}", method = RequestMethod.GET)
@ResponseBody
public String delete(@PathVariable User user)
{
String name = user.getFirstname()+" "+user.getLastname();
userService.delete(user);
return name;
}

application.properties(添加到此行的位是;FILE_LOCK=FS)

spring.datasource.url=jdbc:h2:file:./database.h2;FILE_LOCK=FS 

我注意到在 Spring Boot 中我现在得到以下内容,我知道它引用了我刚刚添加的用于删除的锁定方法,但不确定这是否是我连接被拒绝的原因,因为教程做了同样的事情但有效:

2018-01-24 16:18:54.446 WARN 6589 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Unsupported file lock method "FS " [90060-196] 2018-01-24 16:18:54.447 WARN 6589 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 2018-01-24 16:18:54.447 INFO 6589 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2018-01-24 16:18:54.454 INFO 6589 --- [ restartedMain] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2018-01-24 16:18:54.459 ERROR 6589 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

更新

h2 数据库的文档提到了有关文件锁定的内容,那么为什么这是不受支持的方法?:

File Locking Method 'FS' This is the default mode for version 1.4 and newer. This database file locking mechanism uses native file system lock on the database file. No *.lock.db file is created in this case, and no background thread is started. This mechanism may not work on all systems as expected. Some systems allow to lock the same file multiple times within the same virtual machine, and on some system native file locking is not supported or files are not unlocked after a power failure.

To enable this feature, append ;FILE_LOCK=FS to the database URL.

This feature is relatively new. When using it for production, please ensure your system does in fact lock files as expected.

最佳答案

Spring Boot 应用程序启动似乎失败。你的服务器没有启动。根据日志,创建 bean entityManagerFactory 失败。这是因为, FS 是一种不受支持的文件锁定方法。请检查这是否有效并且是您所需要的。尝试删除它并检查它是否有效。

关于java - Spring ERR_CONNECTION_REFUSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48427589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com