Tag: spring properties

Spring @Value(“$ {}”)通常为null

我正在使用Spring Boot应用程序。 在某些@Component类中,加载@Value字段,而不是在其他类上,它们始终为null 。 似乎在创建@Bean / @Component后加载了@Bean 。 我需要从@Bean的属性文件加载一些值。 你有什么建议吗?

Spring @Value TypeMismatchException:无法将类型’java.lang.String’的值转换为必需类型’java.lang.Double’

我想使用@Value注释来注入Double属性,例如: @Service public class MyService { @Value(“${item.priceFactor}”) private Double priceFactor = 0.1; // … 并使用Spring属性占位符(属性文件): item.priceFactor=0.1 我得到例外: org.springframework.beans.TypeMismatchException:无法将类型’java.lang.String’的值转换为必需类型’java.lang.Double’; 嵌套exception是java.lang.NumberFormatException:对于输入字符串:“$ {item.priceFactor}” 有没有办法使用来自属性文件的Double值?

Spring Boot绑定@Value到Enum不区分大小写

枚举 public enum Property { A, AB, ABC; } 领域 @Value(“${custom.property}”) protected Property property; application.properties (小写) custom.property=abc 当我运行应用程序时,我有一个错误: 无法将[java.lang.String]类型的值转换为必需类型[com.xxx.Property]:找不到匹配的编辑器或转换策略。 鉴于(大写): custom.property=ABC 工作良好。 有没有办法绑定值不区分大小写的值? 像ABC , Abc , AbC , abc任何模式都应该有效。 注意:我看到了这个问题 – Spring 3.0 MVC绑定Enums区分大小写,但在我的情况下,我有超过10个枚举/值(并期望有更多)类并实现10种不同的自定义属性绑定器会很痛苦,我需要一些通用的解决方案。