gpt4 book ai didi

java - org.springframework.expression.spel.SpelParseException : The value cannot be parsed as an int

转载 作者:行者123 更新时间:2023-11-30 08:16:42 27 4
gpt4 key购买 nike

我试图在 int:header 中格式化时间戳,并遇到与 SpEL 相关的奇怪行为(事实上,我已经发现 header-enricher 只能用于静态值,所以我的方法是错误的首先,但我仍然对我遇到的异常感到好奇)。

    <int:header-enricher>
<int:header name="originalFilename" expression="#{T(org.apache.commons.lang3.time.DateFormatUtils).format(new java.util.Date(), 'yyyyMMddhhmm')}"/>
</int:header-enricher>

堆栈跟踪:

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor]: Constructor threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1035E:(pos 26): The value '201504101118' cannot be parsed as an int
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:270) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
... 71 common frames omitted
Caused by: org.springframework.expression.spel.SpelParseException: EL1035E:(pos 26): The value '201504101118' cannot be parsed as an int
at org.springframework.expression.spel.ast.Literal.getIntLiteral(Literal.java:79) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatLiteral(InternalSpelExpressionParser.java:736) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatStartNode(InternalSpelExpressionParser.java:459) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPrimaryExpression(InternalSpelExpressionParser.java:301) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatUnaryExpression(InternalSpelExpressionParser.java:295) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPowerIncDecExpression(InternalSpelExpressionParser.java:251) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatProductExpression(InternalSpelExpressionParser.java:230) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatSumExpression(InternalSpelExpressionParser.java:216) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatRelationalExpression(InternalSpelExpressionParser.java:168) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalAndExpression(InternalSpelExpressionParser.java:156) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalOrExpression(InternalSpelExpressionParser.java:144) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatExpression(InternalSpelExpressionParser.java:104) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:85) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:32) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:76) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:62) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.integration.transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor.<init>(ExpressionEvaluatingHeaderValueMessageProcessor.java:62) ~[spring-integration-core-4.0.4.RELEASE.jar:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_75]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.7.0_75]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.7.0_75]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.7.0_75]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
... 73 common frames omitted
Caused by: java.lang.NumberFormatException: For input string: "201504101118"
at java.lang.NumberFormatException.forInputString(Unknown Source) ~[na:1.7.0_75]
at java.lang.Integer.parseInt(Unknown Source) ~[na:1.7.0_75]
at org.springframework.expression.spel.ast.Literal.getIntLiteral(Literal.java:75) ~[spring-expression-4.0.7.RELEASE.jar:4.0.7.RELEASE]

说真的,为什么是 java.lang.Integer.parseInt?

当我尝试时会发生同样的事情:

#{T(org.apache.commons.lang3.time.DateFormatUtils).format(1428647461944L, 'yyyyMMddhhmm')}"/>

我还发现了这个开放的 jira 问题:https://jira.spring.io/browse/SPR-11021

是否是异常原因?

最佳答案

@rompetroll 的评论是正确的; "#{...}" 语法适用于在上下文初始化时计算一次的静态值。

Spring 集成使用运行时表达式,每次消息到达组件时都会对其进行评估。只需删除 #{}

您正在尝试将静态值注入(inject)需要表达式的属性中。

关于java - org.springframework.expression.spel.SpelParseException : The value cannot be parsed as an int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29556740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com