java - 如何在 Spring XML 配置中将 long 设置为十六进制

标签 java spring

我正在尝试做这样的事情:

<bean id="myBean" class="com.example.SomeThing">
    <property name="longValue">
        <bean class="java.lang.Long">
            <constructor-arg value="0x0418a14372d4186eL" type="long"/>
        </bean>
    </property>
</bean>

但这会导致以下异常:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'java.lang.Long#19190b75' defined in file [/apollo/env/path/to/config.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?

最佳答案

我想你想要factory-method <bean>的参数:

<bean id="myBean" class="com.example.SomeThing">
    <property name="longValue">
        <bean class="java.lang.Long" factory-method="decode">
            <constructor-arg value="0x0418a14372d4186" />
        </bean>
    </property>
</bean>

(请注意缺少“L”后缀。)

关于java - 如何在 Spring XML 配置中将 long 设置为十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14902220/

相关文章:

java - Spring MVC 中 Spring XML 文件的名称

java - 在 Spring Boot 中记录请求负载

java - 使用 azure.keyvault.secret.property-sources 时 Spring Boot 应用程序启动失败并丢失日志

java - 我应该把 META-INF 放在 Gradle 的什么地方?

java - 如何测试采用 Class<T> 的方法

java - FFmpeg 日志记录在 java 命令运行中不起作用

java - 错误找不到函数名称的符号

java - Spring LibGDX And​​roid 应用程序中缺少 java.beans.Introspector

java - 从静态工厂方法创建工厂,然后在该 id 上调用静态工厂方法

java - 使用 websocket spring 初始化进行长轮询回退