gpt4 book ai didi

java - 在 bean 中传递值时出错

转载 作者:行者123 更新时间:2023-12-01 05:48:04 27 4
gpt4 key购买 nike

通过 spring 传递整数时出现错误。

<bean id="propConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/application.properties"/>
</bean>

<bean id="portListenerService" class="com.service.portListenerService" scope="prototype" lazy-init="true" parent="abstractService">
<property name="devicePort" value="${devicePort}"/>
</bean>

portListenerService.java:

@Required
public final void setDevicePort(Integer devicePort) {
this.devicePort= devicePort;
}

这是正确的方法吗?因为我收到错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'portListenerService' defined in ServletContext resource [/WEB-INF/service-config.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 'devicePort'; nested exception is java.lang.IllegalArgumentException: Original must not be null

即使我对端口进行硬编码而不是从 application.properties 中提取它,我也会收到相同的错误。是否还有其他问题?

最佳答案

devicePort 相关代码是否违反了 javabean 规范 - 就像此 discussion

关于java - 在 bean 中传递值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5422996/

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