Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是在xml中自动连接的,不适用于基本数据类型_Java_Xml_Spring - Fatal编程技术网

Java 是在xml中自动连接的,不适用于基本数据类型

Java 是在xml中自动连接的,不适用于基本数据类型,java,xml,spring,Java,Xml,Spring,我尝试这样做,而不是在我的bean类中使用注释。我想使用autowire按类型设置字符串bean中的值。但是这个值是空的。当我使用一个自定义对象(不是一个基本数据类型)时,我会得到我放在引用bean中的值。有人会对这件事大发雷霆吗 Bean.xml: 我有理由相信你不能这样做。我认为你只能注入真实的对象,而不是像人造的本地对象那样的东西。例如:字符串、长字符串等 我建议如果您真的想这样做,您可以使用util:properties构造。这不完全一样,但我认为你可以得到你想要的 或者可能是一张地图

我尝试这样做,而不是在我的bean类中使用注释。我想使用autowire按类型设置字符串bean中的值。但是这个值是空的。当我使用一个自定义对象(不是一个基本数据类型)时,我会得到我放在引用bean中的值。有人会对这件事大发雷霆吗

Bean.xml:
我有理由相信你不能这样做。我认为你只能注入真实的对象,而不是像人造的本地对象那样的东西。例如:字符串、长字符串等

我建议如果您真的想这样做,您可以使用util:properties构造。这不完全一样,但我认为你可以得到你想要的

或者可能是一张地图? 例如:


我不明白问题出在哪里。什么是
null
?给我们一个完整的例子。什么是销售订单?你如何取回你的豆子?
<?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:context="http://www.springframework.org/schema/context"
    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-3.2.xsd">

<bean id="salesorder" class="com.demo.bean.salesorder" autowire="byType">
<property name="orderID" value="100010"></property>
</bean>

<bean id="orderdesc" class="java.lang.String">
<constructor-arg value="This is my first reference use in spring"></constructor-arg>
</bean>

</beans>
<util:map id="filtersByFlag">
   <entry key="${flag.even}" value-ref="filtersForEven" />
   <entry key="${flag.odd}" value-ref="filtersForOdd" />
</util:map>