美好的一天,我正在使用Spring 4.1.1.RELEASE开发一个Web应用程序。所有Spring的配置与注解来实现,它工作得很好,除了一两件事:@Value - >无法将类型'java.lang.String'的值转换为所需类型'java.lang.Integer'

我与这些行项目config.properties文件 cases.caseList.filter=test

cases.caseList.numberOfCasesPerPage=50

我有一个配置类 @Configuration

@ComponentScan(basePackageClasses={CaseConfig.class})

@PropertySource(value = "classpath:config.properties")

public class CasesModuleTestContextConfig { ... }

而另一个类 @Component

public class HttpRequestParamsToPaginationParams extends AbstractConverter, PaginationParams> {

@Value("${cases.caseList.filter}")

private String filter;

@Value("${cases.caseList.numberOfCasesPerPage}")

private Integer count;

...

}

属性“过滤器”的值是从属性资源中成功注入的。但我的财产“计数”得到一个例外:

13:58:45.274 [main] WARN o.s.c.s.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cz.pokus.core.test.config.ConversionServiceTestConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.List cz.pokus.core.test.config.ConversionServiceTestConfig.converterList; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpRequestParamsToPaginationParams': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.Integer cz.pokus.core.cases.converter.HttpRequestParamsToPaginationParams.count; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "${cases.caseList.numberOfCasesPerPage}"

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.1.RELEASE.jar:4.1.1.RELEASE]

...

Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "${cases.caseList.numberOfCasesPerPage}"

...

Caused by: java.lang.NumberFormatException: For input string: "${cases.caseList.numberOfCasesPerPage}"

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_20]

at java.lang.Integer.parseInt(Integer.java:569) ~[na:1.8.0_20]

at java.lang.Integer.valueOf(Integer.java:766) ~[na:1.8.0_20]

...

当我改变属性字符串“计数”的类型就开始工作:

@Value("${cases.caseList.numberOfCasesPerPage}")

private String count;

我相信春天是能够转换成字符串当使用@Value将属性资源的值注入到Integer属性中时为Integer。我发现了一些人们没有抱怨的例子。你有什么想法,为什么它不适合我?

非常感谢。

2014-11-24

Vojtech

+2

它工作还是刚启动没有错误。在这种情况下,我希望这个值字面上是'$ {cases.caseList.numberOfCasesPerPage}'。确保你已经将'PropertySourcesPlaceHolderConfigurer'注册为'public static' bean。 –

2014-11-24 13:44:59

java不能对什么类型进行转换_@Value - 无法将类型'java.lang.String'的值转换为所需类型'java.lang.Integer'...相关推荐

  1. 【java运行报错】Can not set java.lang.String field com.iS.UserEntity.name to java.lang.Class

    [java运行报错]Can not set java.lang.String field com.iS.UserEntity.name to java.lang.Class 原因: 解决办法 总结:仰 ...

  2. python变量类型之间转换_【Python】Python 变量类型(变量赋值,数据类型,数据转换)...

    目录 Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间.基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中.因此,变量可以指定不同的数 ...

  3. bool类型数组转换成一个整数_Go 学习笔记 02 | 基本数据类型以及 byte 和 rune 类型...

    一.基本数据类型 unsafe.Sizeof() 查看不同长度的整型在内存中的存储空间. 类型转换,高位向低位转换要注意溢出. 数字字面量语法. 64 位系统中 Go 语言中浮点数默认是 float6 ...

  4. mybatis 传递parameterType=java.lang.String对值的判断

    严重: Servlet.service() for servlet [springmvc] in context with path [/superben] threw exception [Requ ...

  5. java中时间入数据库格式转换_数据库中字段类型为datetime,转换成java中的Date类型...

    数据类型对照 点击打开链接 JDBC: PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuer ...

  6. java不能对什么类型进行转换_关于java:“不兼容类型:void无法转换为…”是什么意思?...

    Java编译消息是什么: "Incompatible types: void cannot be converted to ..." 的意思,以及我该如何解决. 一些编译器使用不同 ...

  7. Java字节序与大小端转换_什么时候要进行大小端字节序的转换? | 学步园

    什么时候要进行大小端字节序的转换? 通过socket收发数据(在intel的处理器上), 什么时候要进行大小端字节序的转换? 比如发一个int型的数据出去,要不要进行转换? 还是两端一样,就不用考虑转 ...

  8. Java开发专业通过swot分析岗位_掌起智能科技 | 你们要的安卓岗位来了,还有JAVA,技术经理等岗位...

    成都IT内推圈成立于2016年,专注成都IT互联网领域的招聘与求职;覆盖精准IT人群10W+,通过内推圈推荐且已入职人数超过5000+,合作公司均系成都知名或靠谱公司. 此公众号每天7:30AM准时推 ...

  9. java编程10以内随机数字乘除_随机生成10个长度为10以内的字符串并排序(Java入门第三季集合下作...

    作业要求: 实现代码: package JiHe; import java.util.List; import java.util.Collections; import java.util.Arra ...

  10. java输出栈的弹出序列_剑指offer:栈的压入、弹出序列(Java)

    1.题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是 ...

最新文章

  1. 解决:【异常】Caused by: java.lang.IllegalStateException: Zip64 archives are not supported
  2. 桌面虚拟化场景中对存储系统IO性能的评估方法
  3. Jenkins+.Net Core+Git集成发布 - SkyMallCore快速开发平台
  4. 索引语法——创建索引 || 查看索引 || 删除索引 || ALTER命令 索引设计原则
  5. boost::intrusive::any_base_hook用法的测试程序
  6. 要闻君说:微软拿下五角大楼超大云服务订单!恒大玩儿起了充电桩and新能源汽车?苹果公司要放弃自动驾驶业务?...
  7. GIS和RS里面的一些小问题
  8. Springboot07配制数据统一返回格式以及定义统一的异常处理类
  9. 避免软件失败的7个关键实践——来自项目管理群的讨论
  10. Tree树结构java实现
  11. (第十二章)创建数据表索引
  12. vscode配置C++ CMake项目
  13. MapWinGis入门
  14. 纵向取模需要自己倒叙吗_我能自己完成混音工作吗?需要掌握哪些知识?
  15. @property 参数问题
  16. JAVA-JDK环境变量配置
  17. 一二线城市知名IT互联网公司名单!
  18. 中文期刊分类(blog版)
  19. 纯平显示器_绿色计算:切换到液晶纯平显示器
  20. 【转】联普多WAN口路由器是否可以设置叠加带宽

热门文章

  1. tp3.2 隐藏index.php,thinkphp3.2.3隐藏index.php入口文件
  2. c vb语言代码大全下载,VB编程常用代码大全
  3. 解决linux中tmp目录下的文件被清理的问题
  4. java 类 引用数组对象_Java 方法重载与引用数组类型
  5. flutter 动画json_flutter常用内置动画组件
  6. win7 mysql zip包如何安装_MySql 5.7.31 win7 Zip压缩包配置教程
  7. 动态库的隐式链接和显示链接
  8. 按月分表(create table)
  9. 数据结构与算法---常用三大排序算法
  10. hdu 5187 zhx's contest