简体   繁体   English

春季ERR_CONNECTION_REFUSED

[英]Spring ERR_CONNECTION_REFUSED

I am following a tutorial on spring, and so far my code allows you to add a user and view all users. 我正在阅读关于Spring的教程,到目前为止,我的代码允许您添加用户并查看所有用户。 I am now trying to include delete functionality. 我现在试图包括删除功能。 I added the below code to achieve this. 我添加了以下代码以实现此目的。 I believe it is exactly as shown in the tutorial, but as a result I get ERR_CONNECTION_REFUSED. 我相信它与本教程中显示的完全一样,但是结果我得到了ERR_CONNECTION_REFUSED。 In the tutorial this error showed initially but upon refresh went away, but in my case it does not. 在本教程中,最初显示了此错误,但刷新后消失了,但在我看来,它没有。

index.html 的index.html

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

userService.java userService.java

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

userController.java userController.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 (the bit added to this line is ;FILE_LOCK=FS ) application.properties(添加到此行的位是;FILE_LOCK=FS

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

I noticed in spring boot I now get the following, which I know references the lock method I just added for deleting, but not sure if this is why I am getting connection refused as the tutorial did the same thing but worked: 我注意到在Spring Boot中,我现在得到以下信息,我知道它引用了我刚刚添加的用于删除的lock方法,但不确定这是否是为什么我被拒绝连接的原因,因为本教程做了同样的事情但起作用了:

2018-01-24 16:18:54.446 WARN 6589 --- [ restartedMain] ohejeiJdbcEnvironmentInitiator : 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; 2018-01-24 16:18:54.446警告6589 --- [restartMain] ohejeiJdbcEnvironmentInitiator:HHH000342:无法获得与查询元数据的连接:不支持的文件锁定方法“ FS” [90060-196] 2018-01-24 16:18 :54.447 WARN 6589 --- [restartedMain] ationConfigEmbeddedWebApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建类名称为'entityManagerFactory'的bean时在类路径资源[org / springframework / [boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]:调用init方法失败; 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 : 嵌套的异常是org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 2018-01-24 16:18:54.447信息6589-[重新启动] o.apache.catalina.core.StandardService:正在停止服务[Tomcat] 2018-01-24 16:18:54.454信息6589 --- [restartedMain] utoConfigurationReportLoggingInitializer:

Error starting ApplicationContext. 启动ApplicationContext时出错。 To display the auto-configuration report re-run your application with 'debug' enabled. 要显示自动配置报告,请在启用“调试”的情况下重新运行您的应用程序。 2018-01-24 16:18:54.459 ERROR 6589 --- [ restartedMain] osboot.SpringApplication : Application startup failed 2018-01-24 16:18:54.459错误6589 --- [restartedMain] osboot.SpringApplication:应用程序启动失败

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; org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]中定义的名称为'entityManagerFactory'的bean时出错:调用init方法失败; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 嵌套的异常是org.hibernate.service.spi.ServiceException:无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

UPDATE UPDATE

Documentation for h2 database says this about file lock, so why would this be an unsupported method?: h2数据库的文档说明了有关文件锁定的信息,那么为什么这是不受支持的方法?

File Locking Method 'FS' This is the default mode for version 1.4 and newer. 文件锁定方法'FS'这是1.4版及更高版本的默认模式。 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. 在这种情况下,不会创建* .lock.db文件,并且不会启动任何后台线程。 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. 要启用此功能,请将; FILE_LOCK = FS附加到数据库URL。

This feature is relatively new. 此功能是相对较新的。 When using it for production, please ensure your system does in fact lock files as expected. 在将其用于生产时,请确保事实上系统确实按预期锁定了文件。

Spring Boot application startup seems to be failed. Spring Boot应用程序启动似乎失败。 Your sever is not started. 您的服务器未启动。 As per the logs, creation of bean entityManagerFactory failed. 根据日志,创建bean entityManagerFactory失败。 This because, FS is an Unsupported file lock method . 这是因为FSUnsupported file lock method Kindly check if this is valid and is what you need. 请检查这是否有效,是您所需要的。 Try removing this and check if it works. 尝试删除它并检查它是否有效。

spring.datasource.driver-class-name=org.h2.Driver

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

spring.jpa.hibernate.ddl-auto=update

Just incase someone else encounters the same problem, adding the third line fixes this issue. 万一其他人遇到相同的问题,添加第三行即可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导应用程序:net::ERR_CONNECTION_REFUSED - Spring Boot application: net::ERR_CONNECTION_REFUSED 码头工人微服务err_connection_refused - docker microservice err_connection_refused Stackify 前缀 sfclient ERR_CONNECTION_REFUSED - Stackify Prefix sfclient ERR_CONNECTION_REFUSED Tomcat管理器ERR_CONNECTION_REFUSED - Tomcat manager ERR_CONNECTION_REFUSED 从OncePerRequestFilter(Java + Spring)抛出与net :: ERR_CONNECTION_REFUSED不同的错误 - Throw different error than net::ERR_CONNECTION_REFUSED from OncePerRequestFilter ( Java + Spring ) Selenium/TestBench 失败:net::ERR_CONNECTION_REFUSED - Selenium/TestBench failure: net::ERR_CONNECTION_REFUSED 如果我在春季使登录页面使用&#39;https&#39;,如何避免错误102(net :: ERR_CONNECTION_REFUSED)? - If I make my login page use 'https' in Spring, how do I avoid Error 102 (net::ERR_CONNECTION_REFUSED)? tomcat10主页无法通过键入localhost加载:8080错误:ERR_CONNECTION_REFUSED - tomcat10 home page can not load by typing localhost:8080 error: ERR_CONNECTION_REFUSED 在 IIS 服务器上运行的 Angular FE:对 http://localhost:8080/api 的 POST 请求生成 net::ERR_CONNECTION_REFUSED - Angular FE running on IIS server: POST request to http://localhost:8080/api generates net::ERR_CONNECTION_REFUSED Spring App cloudfoundry:连接被拒绝 - Spring App cloudfoundry : connection refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM