项目通用文件配置目录

reids配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache"xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd   http://www.springframework.org/schema/mvc   http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/cache  http://www.springframework.org/schema/cache/spring-cache.xsd">  <!-- redis 相关配置 --> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  <property name="maxIdle" value="${redis.maxIdle}" />   <property name="maxWaitMillis" value="${redis.maxWait}" />  <property name="testOnBorrow" value="${redis.testOnBorrow}" />  </bean>  <bean id="JedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/>  <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">  <property name="connectionFactory" ref="JedisConnectionFactory" />  </bean>  </beans>  

报错内容:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'poolConfig' defined in URL [jar:file:/H:/repository_pinyougou/com/pinyougou/pinyougou-common/0.0.1-SNAPSHOT/pinyougou-common-0.0.1-SNAPSHOT.jar!/spring/applicationContext-redis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'maxIdle'; nested exception is java.lang.NumberFormatException: For input string: "${redis.maxIdle}"at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)at java.util.concurrent.FutureTask.run(Unknown Source)at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'maxIdle'; nested exception is java.lang.NumberFormatException: For input string: "${redis.maxIdle}"at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:596)at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:204)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1527)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)... 20 more
Caused by: java.lang.NumberFormatException: For input string: "${redis.maxIdle}"at java.lang.NumberFormatException.forInputString(Unknown Source)at java.lang.Integer.parseInt(Unknown Source)at java.lang.Integer.valueOf(Unknown Source)at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:194)at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:113)at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:464)at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:437)at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:195)at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)... 26 more

观察报错原因 为 :

Failed to convert property value of type [java.lang.String] to required type [int] for property 'maxIdle'; nested exception is java.lang.NumberFormatException: For input string: "${redis.maxIdle}"

未能将java.lang.string类型的文件转换成maxIdle属性需要的int类型 为数据转换类型错误

仔细分析后:

原来是在测试时,没有导入redis.properties文件,value把${redis.maxIdle}解析为字符串,所以会报: For input string: "${redis.maxIdle}"异常。实际在项目部署启动tomcat后就不会报这样的异常,因为不会获取不到配置文件。

更改方法:

在spring配置文件目录下apllicationContext-redis中添加

<context:property-placeholder location="classpath*:properties/*.properties" />  

修改后的application-redis.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache"xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd   http://www.springframework.org/schema/mvc   http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/cache  http://www.springframework.org/schema/cache/spring-cache.xsd">  <context:property-placeholder location="classpath*:properties/*.properties" />  <!-- redis 相关配置 --> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  <property name="maxIdle" value="${redis.maxIdle}" />   <property name="maxWaitMillis" value="${redis.maxWait}" />  <property name="testOnBorrow" value="${redis.testOnBorrow}" />  </bean>  <bean id="JedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/>  <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">  <property name="connectionFactory" ref="JedisConnectionFactory" />  </bean>  </beans>  

修改完成后,项目正常运行。

关于java.lang.NumberFormatException: For input string:${redis.maxIdle}的报错相关推荐

  1. swagger报错 java.lang.NumberFormatException: For input string: ““

    项目中集成Swagger,每次刷新页面,都给我报一个java.lang.NumberFormatException: For input string: ""的错误,真的是犯强迫症 ...

  2. java.lang.NumberFormatException: For input string: “name”

    背景:action中查询出list数据需要在前台进行显示,但根据主键在数据库中查询出的数据list中含有熟悉alist属性为配置表,且支持用户多选,前端通过el表达式显示 前台界面为:<c:fo ...

  3. 访问swagger/Knife4j 接口文档报错:java.lang.NumberFormatException: For input string: ““

    目录 问题描述 解决过程 问题描述 报异常如下:java.lang.NumberFormatException: For input string: "" 虽然不影响使用,但是每次 ...

  4. Failed to build custom metric java.lang.NumberFormatException: For input string: “∞“

    背景:计算除法的时候,部分数据计算时报错,报错: Failed to build custom metric java.lang.NumberFormatException: For input st ...

  5. 关于Swagger报错java.lang.NumberFormatException: For input string: 的总结

    关于Swagger报错java.lang.NumberFormatException: For input string: ""的总结 1 为什么会报错? 2 如何排错? 3 哪种 ...

  6. mybatis 报错:Cause: java.lang.NumberFormatException: For input string

    Cause: java.lang.NumberFormatException: For input string 异常提示 异常来源 异常解决 异常提示 Error querying database ...

  7. mybatis 报错:Cause: java.lang.NumberFormatException: For input string: ““

    mybatis 报错:Cause: java.lang.NumberFormatException: For input string: "" 问题描述 我使用的mybatis版本 ...

  8. Mybatis报错: Error querying database. Cause: java.lang.NumberFormatException: For input string: “A“

    报错信息:Error querying database. Cause: java.lang.NumberFormatException: For input string: "A" ...

  9. java.lang.NumberFormatException: For input string:

    原因:这个异常是说,在将字符串""转换为number的时候格式化错误. 额,很简单的异常,以前我是写个方法,然后遍历对比不正确的数字或者用正则表达式之类的.现在发现一个很漂亮的方法 ...

最新文章

  1. redis(3)redis的基础入门(java)
  2. cocos2dx-lua之断点调试支持
  3. hadoop关闭安全模式
  4. Linux基础篇之文本、数据流处理命令(sed uniq grep awk wc)
  5. 协同旋转不变网格形变
  6. WPF 放大镜(Magnifying Glass)
  7. CE下基于Zylonite硬件平台的SD卡驱动开发
  8. IDEA包的分层显示
  9. killall 后面信号_Linux killall命令及信号
  10. 景霄讲解Python部分内部实现
  11. Cobbler详解(四)——CentOS7系统导入
  12. 揭秘《英雄联盟》的游戏自动化测试
  13. 计算机cpu执行时间 指令条数的单位,计算机原理2015年10月真题(02384)
  14. SaaS 公司融资的「22条军规」
  15. 二、三级等保申请流程,二、三级等保怎么申请?二、三级等保是什么?等保测评需要多少钱?
  16. java关闭端口_使用java代码关闭指定端口的程序-windows
  17. Java小白的数据库爱情(四)Oracle DDL、DML使用
  18. 华三交换机irf 堆叠配置_交换机的堆叠配置
  19. C#OOP之八 继承 接口和抽象类
  20. 百度网盘全速下载破解工具

热门文章

  1. 软件系统设计-10-防御式编程
  2. 【ELK】heima教程elk学习
  3. 2022年青海最新建筑施工信号工(建筑特种作业)模拟考试题库及答案
  4. 阿里技术高P访谈之“呆萌”程序员蒋晓伟为何从Facebook到阿里巴巴
  5. java里next 和nextline_详解Java中方法next()和nextLine()的区别与易错点
  6. php操作剪贴板内容代码,详细解答JS操作剪贴板
  7. 专访政协委员陈朝晖:泉州区块链政策解读
  8. 计算两个有序数组的中位数
  9. 微信小程序 实现个人用户界面
  10. CPU各个寄存器作用