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'
  • 相关阅读:
    分页存储过程
    调存储过程
    winform httplicent调用API
    存储过程,触发器,等等。。。
    C# AJAXform上传图片
    Mysql order by与limit联用出现的问题
    将Sublime Text 3 放到右键中
    Vue-cli构建步骤
    Javascript面试知识点
    position详解
  • 原文地址:https://www.cnblogs.com/exmyth/p/10442071.html
Copyright © 2011-2022 走看看