I'm using Spring Boot version 2.1.9.RELEASE with web, session, security, jdbc and jpa starters. Everything is ok in my application, until I try to override the default session timeout value, with the following line in the application.properties:
server.servlet.session.timeout=180
If this line is added, when starting Spring I get the following error:
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
I also tried different formats, such as 180s or PT180S, but nothing worked. According to Spring documentation or other variants of the same doc, the version with only the integer should be correct
Further customization is possible using application.properties:
src/main/resources/application.properties server.servlet.session.timeout= # Session timeout. If a duration suffix is not specified, seconds will be used.
Another documentation page explains the other formats and I understand that the standard should work, without declaring beans (I understand that is Spring boot itself who is declaring the standard ConverstionService, is it correct? Or should I specify something in my @Configuration class?).
I really don't understand what I'm missing, please help me.
EDIT: I also tried to explicitly expose an ApplicationConversionService bean as explained in another question, but it doesn't work, exactly same result as before.