[spring-projects/spring-boot]当 user.language=tr 时 Spring Boot 应用程序无法启动

2024-04-29 67 views
7

覆盖 application.properties 中的 Jackson 配置,即

spring.jackson.mapper.accept-case-insensitive-properties=false

导致应用程序无法启动并出现以下错误:

$ java -Duser.language=tr -jar springboot-localebugdemo-0.0.1-SNAPSHOT.jar
20:45:12.014 [main] INFO springboot.localebugdemo.LocaleBugDemoApplication - user.language=tr

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.10.RELEASE)

2018-02-25 20:45:12.683  INFO 3448 --- [           main] s.l.LocaleBugDemoApplication             : Starting LocaleBugDemoApplication on DanBarMBP with PID 3448 (/Users/danbar/Projects/lab/springboot-localebugdemo/build/libs/springboot-localebugdemo-0.0.1-SNAPSHOT.jar started by danbar in /Users/danbar/Projects/lab/springboot-localebugdemo/build/libs)
2018-02-25 20:45:12.684 DEBUG 3448 --- [           main] s.l.LocaleBugDemoApplication             : Running with Spring Boot v1.5.10.RELEASE, Spring v4.3.14.RELEASE
2018-02-25 20:45:12.684  INFO 3448 --- [           main] s.l.LocaleBugDemoApplication             : No active profile set, falling back to default profiles: default
2018-02-25 20:45:14.157  INFO 3448 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-02-25 20:45:14.159  INFO 3448 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.27
2018-02-25 20:45:14.267  INFO 3448 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-02-25 20:45:14.489 ERROR 3448 --- [           main] o.s.b.b.PropertiesConfigurationFactory   : Properties configuration failed validation
2018-02-25 20:45:14.490 ERROR 3448 --- [           main] o.s.b.b.PropertiesConfigurationFactory   : Field error in object 'spring.jackson' on field 'null': rejected value [accept-case-insensitive-properties]; codes [typeMismatch.spring.jackson.null,typeMismatch.null,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.jackson.null,null]; arguments []; default message [null]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'com.fasterxml.jackson.databind.MapperFeature' for property 'null'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [com.fasterxml.jackson.databind.MapperFeature] for value 'accept-case-insensitive-properties'; nested exception is java.lang.IllegalArgumentException: No enum constant com.fasterxml.jackson.databind.MapperFeature.accept-case-insensitive-properties]
2018-02-25 20:45:14.492  WARN 3448 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'standardJacksonObjectMapperBuilderCustomizer' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration.class]: Unsatisfied dependency expressed through method 'standardJacksonObjectMapperBuilderCustomizer' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties': Could not bind properties to JacksonProperties (prefix=spring.jackson, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult: 1 errors
Field error in object 'spring.jackson' on field 'null': rejected value [accept-case-insensitive-properties]; codes [typeMismatch.spring.jackson.null,typeMismatch.null,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.jackson.null,null]; arguments []; default message [null]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'com.fasterxml.jackson.databind.MapperFeature' for property 'null'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [com.fasterxml.jackson.databind.MapperFeature] for value 'accept-case-insensitive-properties'; nested exception is java.lang.IllegalArgumentException: No enum constant com.fasterxml.jackson.databind.MapperFeature.accept-case-insensitive-properties]
2018-02-25 20:45:14.495  INFO 3448 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-02-25 20:45:14.521 ERROR 3448 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Binding to target org.springframework.boot.autoconfigure.jackson.JacksonProperties@4b4523f8 failed:

    Property: spring.jackson.null
    Value: accept-case-insensitive-properties
    Reason: Failed to convert property value of type 'java.lang.String' to required type 'com.fasterxml.jackson.databind.MapperFeature' for property 'null'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [com.fasterxml.jackson.databind.MapperFeature] for value 'accept-case-insensitive-properties'; nested exception is java.lang.IllegalArgumentException: No enum constant com.fasterxml.jackson.databind.MapperFeature.accept-case-insensitive-properties

Action:

Update your application's configuration

相同的应用程序,开始user.language=en(也尝试了一些其他语言)工作正常。似乎任何 Spring Boot 应用程序(即使是新生成的,如附件 zip 中的应用程序)都会受到影响。

springboot-localebugdemo.zip

回答

4

使用 Spring Boot 2.0.0.RC2 进行测试。工作正常。

5

@danbar74,因为我怀疑这个应用程序对我来说工作得很好(以及我从 start.spring.io 使用该属性创建的应用程序)。此时我最好的猜测是,当您升级到1.5.10.您可以检查您的 gradle 缓存并尝试再次下载这些位吗?

0

损坏的库不太可能是原因,因为我从 3 台不同计算机上构建的应用程序中得到了相同的结果。我将擦除 gradle 缓存并重新测试。只是为了仔细检查 - 你运行你的应用程序了-Duser.language=tr吗?

8

正如我怀疑的那样,清除 gradle 缓存 ( rm ~/.gradle/caches) 并重建应用程序没有什么区别。附加应用程序,以防万一您想仔细检查损坏的库。 springboot-localebugdemo-0.0.1-SNAPSHOT.jar.zip

6

我可以复制这个。问题出在StringToEnumIgnoringCaseConverterFactory它调用的时候enum.name().toLowerCase()。结果是accept-case-ınsensıtıve-propertıes而不是accept-case-insensitive-properties出于某种原因。请注意,s 中缺少点i

1

我想我们应该toLowerCaseUTF-8 Locale.

9

您对使用与 2.0.0.RC2 相同的方法有何看法 -String.toLowerCase()根本不使用(工作得很好,我测试过)?

5

@danbar74 2.0.0 仍然有一个调用,它是此流toLowerCase的一部分。 “根本不使用”是什么意思?还有什么选择呢?string.toLowerCase()

8

我们应该重新审视所有使用toLowerCaseadd的情况Locale.ENGLISH

@danbar74 抱歉我忽略了有关用户区域设置的部分。

4

@philwebb 是的,toLowerCase()仍在使用,但Character#toLowerCase()不是String#toLowerCase()。无论如何,我猜@snicoll 建议通过指定Locale.ENGLISH而不是依赖默认值来修复 1.5.x,这是最小/最安全的更改,它也应该解决问题。

7

@danbar74 我继续测试了你的项目(这次是正确的!),它与1.5.11.BUILD-SNAPSHOT.一旦此构建完成,新的快照应该很快就会可用。如果你能尝试一下那就太好了。

4

重新打开看看我们是否可以为此添加测试(可能不可能)

3

@snicoll 已测试,现在按预期工作,谢谢。