当前位置: 首页 > 知识库问答 >
问题:

Spring启动超时配置异常

干善
2023-03-14

我正在使用Spring Boot版本2.1.9。带有Web、会话、安全、jdbc和jpa启动器的RELEASE。在我的应用程序中一切正常,直到我尝试覆盖默认会话超时值,application.properties中有以下行:

server.servlet.session.timeout=180

如果添加这一行,在启动Spring时,我会得到以下错误:

2019-12-02 17:48:17.689  INFO 12824 --- [           main] o.a.c.c.C.[.[localhost].[/webapp]        : Initializing Spring embedded WebApplicationContext 
2019-12-02 17:48:17.689  INFO 12824 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 11388 ms 
2019-12-02 17:48:17.955  WARN 12824 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:  org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.session-org.springframework.boot.autoconfigure.session.SessionProperties': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.session.SessionProperties]: Constructor threw exception; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'server-org.springframework.boot.autoconfigure.web.ServerProperties': Could not bind properties to 'ServerProperties' : prefix=server, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'server.servlet.session.timeout' to java.time.Duration 
2019-12-02 17:48:17.971  INFO 12824 --- [           main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 
2019-12-02 17:48:17.971 ERROR 12824 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

 *************************** APPLICATION FAILED TO START
 ***************************

 Description:

 Failed to bind properties under 'server.servlet.session.timeout' to java.time.Duration:

     Property: server.servlet.session.timeout
     Value: 180
     Origin: "server.servlet.session.timeout" from property source "URL [file:C:/Users/utente/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/configurazioni/application.properties]"
     Reason: failed to convert java.lang.String to @org.springframework.boot.convert.DurationUnit java.time.Duration

 Action:

Update your application's configuration

我还尝试了不同的格式,如180s或PT180S,但都不起作用。根据Spring文档或同一文档的其他变体,只有整数的版本应该是正确的

可以使用应用程序进行进一步定制。属性:

src/main/resources/application。属性服务器。servlet。一场超时=#会话超时。如果未指定持续时间后缀,则将使用秒。

另一个文档页面解释了其他格式,我知道标准应该可以工作,而不需要声明bean(我知道是Spring boot本身声明了标准ConversationService,对吗?还是应该在@Configuration类中指定一些内容?)。

我真的不明白我错过了什么,请帮帮我。

编辑:我还尝试显式公开一个Application ationConversionService bean,如另一个问题中所述,但它不起作用,结果与之前完全相同。

共有1个答案

蓟捷
2023-03-14

好的,解决了,多亏了一个collegue:它只是值后面的一个空格(非常惊讶没有修剪空格!)

 类似资料:
  • 我使用的是Spring Boot版本2.0.6.RELEASE 我有以下 API 方法 getSearchData方法运行大约需要40秒。30秒后,我的代码超时,日志中显示以下消息: 并返回以下json响应 getSearchData()方法继续执行,并最终在日志中显示为完成。如果我去掉未来返回类型,只返回一个列表,代码就能正常工作。我已经尝试了以下属性,但不幸的是没有成功。 有谁知道我需要做些什

  • 我对Spring Boot cassandra web应用程序有问题。随着数据的增长,它开始出现,现在它是一个非常常见的场景。 所有查询有时都不起作用,返回。几秒钟后它又开始工作了,几秒钟后它就不工作了。所以web应用程序不断返回或响应。相同的查询始终在中工作。 我正在使用: Spring启动启动程序 sping-boo-starter-data-cassandra#2.1.3 Cassandra

  • 我试图在Intellij终极版15.0.4中配置Spring Boot运行配置。完成以下工作。 单击以创建新的Spring Boot配置 添加了主类、VM选项、JRE和环境变量 我无法在Spring Boot设置下找到启用启动优化和启用JMX代理?谁能推荐一下吗

  • 我有这个类来启动SpringCloudConfig服务器。这是一个Spring Boot应用程序。 应用程序运行正常,我的所有单元测试都正常。然而,在我们的竹子管道中,它将初始一个声纳过程来分析代码。我们不断收到这些小警告,表示以下内容: 我知道这是一个小问题,但我的任务是从代码中删除这些内容。 理想情况下,您应该将类标记为final并提供一个私有构造函数,或者所有搜索都提供一个解决方案。但是,S

  • 我从一个工作的Spring配置的Web应用程序开始,并且一直在Spring上下文配置文件中的beans标记中添加Spring配置文件: