Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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 Spring:使用上下文时,默认值始终被覆盖:?_Java_Spring - Fatal编程技术网

Java Spring:使用上下文时,默认值始终被覆盖:?

Java Spring:使用上下文时,默认值始终被覆盖:?,java,spring,Java,Spring,如果我有: <?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:util="http://www.springframework.org/schema/util" xmlns:context="http://w

如果我有:

<?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:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:property-placeholder location="classpath:${PropertiesFile}" ignore-unresolvable="false" ignore-resource-not-found="false" />

    <bean id="SpringMailSender" class="${MailSenderClass:org.mypackage.MockJavaMailSenderImpl}">
        <property name="host" value="localhost" />
    </bean>
</beans>
我希望org.mypackage.MockJavaMailSenderImpl类不会被使用,但它总是被使用。我通常不会看到这种行为,默认值也不会像预期的那样工作。我很难找到这里发生的事情。我正在通过删除默认值并确保我的属性文件都指定此属性来解决此问题


有人能解释一下它为什么会这样做,以及如何让默认设置像我在本例中预期的那样工作吗?

我不确定这会有什么帮助,因为我只需要一个bean,并且拥有多个错误类的bean实例不会改善这种情况。非常简单,如果我没有指定覆盖,它将使用属性文件中的内容:这是它首先应该做的。我认为您不了解这种情况。您的属性文件本身是占位符位置,对吗?您能否尝试不使用占位符,并根据由于org.springframework.beans.factory.config.propertyplaceholderconfigure不会产生相同类型的问题,因此,file.似乎是上下文本身的问题。我遇到了类似的问题,原因是我有另一个问题
MailSenderClass=org.springframework.mail.javamail.JavaMailSenderImpl