Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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 systemProperties键-IllegalArgumentException:键不能为null_Java_Spring_Annotations - Fatal编程技术网

Java spring systemProperties键-IllegalArgumentException:键不能为null

Java spring systemProperties键-IllegalArgumentException:键不能为null,java,spring,annotations,Java,Spring,Annotations,我的appContext.xml中有这个 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>file:pathTo/service.properties</value>

我的appContext.xml中有这个

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>file:pathTo/service.properties</value>
            <value>file:pathTo/configuration.properties</value>
        </list>
    </property> 
</bean>
这就行了,我在url中得到了myServiceKey的值

但我想在myServiceKey不存在时使用默认值,所以我尝试了这个方法

@Value("${myServiceKey:defaultValue}")
private String url;
它总是设置“defaultValue”,而不是正确的“myServiceKey”

我还意识到,使用这个:

@Value("#{systemProperties['myServiceKey']}")
private String url;
我有个例外

WARN  MSF4JMessageProcessor:262 - Unmapped exception -java.lang.IllegalArgumentException: URI must not be null
这有关系吗?怎么了

我使用的是spring版本4.3.9.0


提前感谢。

我认为
MSF4JMessageProcessor:262-Unmapped exception-java.lang.IllegalArgumentException:URI不能为null
与您的问题无关

我们一直在使用默认值,没有任何问题。只是想树立一些榜样

mail.properties

smtp.port=587
myServiceKey=s3cr3t
user.dir=D:\Java
控制器类:

@Controller
public class HelloWorldController {

   @Value("${myServiceKey: H3ll0W0rld}")
    private String myServiceKey;
    ...
   @RequestMapping("/index")
   public String index(){
     System.out.println("myServiceKey = "+myServiceKey);
     ... 
   }
}
此代码正确打印myServiceKey=s3cr3t。当我更新我的
mail.properties
如下时

smtp.port=587
user.dir=D:\Java

它打印myServiceKey=H3ll0W0rld

最后我发现了问题,原因是我在PropertyPlaceHolderConfigure中有多个属性。 我发现它在:

这里提出的解决方案对我来说很有效

我将PropertyPlaceHolderConfigurer分为两个不同的配置,并在其中一个配置中添加了PropertyValueSeparator

<property name="valueSeparator" value="="/>

现在它起作用了。希望它能帮助其他人。

嗨,谢谢你的回答。我知道,这应该行得通。但正如我在问题的第一部分所说,当“:”存在时,它没有采用正确的值。它使用“H3ll0W0rld”代替。问题是,当我不尝试设置默认值时,它可以正常工作。。。属性文件的设置可能有问题??
<property name="valueSeparator" value="="/>
@Value("${myServiceKey= H3ll0W0rld}")