zoukankan      html  css  js  c++  java
  • Spring配置文件中条件判断标签

    <bean id="propertyConfigurer"
    	class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	<property name="locations">
    		<array>
    			<value>classpath:/settings.properties</value>
    		</array>
    	</property>
    </bean>
    <constructor-arg name="password" value="#{'${redis.password}'?:null}"></constructor-arg>
    <!--表示当redis.password不为空时,那么返回redis.password,否则返回null -->
    <!-- 或者可以如下表示那么含义就更清晰了-->
    <constructor-arg name="password" value="#{'${redis.password}'!=''?'${redis.password}':null}"></constructor-arg>

    setting.properties:

    redis.masterName=mymaster
    redis.password=
    redis.number=0

    注意:一定要给${redis.password}显式加上单引号,否则它就会被解析为bean。从而报错:

    Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'foobared' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
  • 相关阅读:
    Objective-C实用类和协议
    KVC(Key-Value-Coding)和KVO(Key-Value-Observer)
    Xcode
    IOS模拟器
    沙盒机制
    UIScrollView
    NSPredicate
    输入控件适应键盘
    10步成为专业iOS开发者——新手向,从零起步
    2015 年五大移动端设计趋势
  • 原文地址:https://www.cnblogs.com/exmyth/p/10442071.html
Copyright © 2011-2022 走看看