Announcement Announcement Module
Collapse
No announcement yet.
default value inside @Value overrides properties file value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • default value inside @Value overrides properties file value

    Hi,
    I am using Spring 3.1.1.RELEASE. I have following code.
    Code:
    	@Value("${enableSiteMap}")
    	private Boolean enableSiteMap;
    
    	@PostConstruct
    	public void initKeyMap(){
    		if(!enableSiteMap){
    			logger.info("NOT intitlizing keys map and site map...");
    			return;
    		}
                    // do something to populate a map.
    	}
    this works fine and reads values from properties file. but if I give default value in @Value
    Code:
    	@Value("${enableSiteMap:true}")
    	private Boolean enableSiteMap;
    the above always takes enableSiteMap as true. (same holds for '${enableSiteMap:false}' the enableSiteMap is always false).
    if I dont give any default value everything works perfectly i.e picks from props file. but if the propertiy are missing it will fail.
    am I missing anything?

  • #2
    I am also facing same issue

    Can someone please share their views on this issue...

    I am also facing same issue......The default value overrides the value from properties file......how to stop that.....

    Comment


    • #3
      Hi,

      I solved as shown below....

      Inside my controller
      Code:
      @Autowired
      @Value("#{props.getProperty('myProperty') ?: 7}")
      private String myPropertyStr;
      In my xml file:
      Code:
      <util:properties id="props" location="classpath:jdbc.properties" local-override="false" ></util:properties>
      In my jdbc.properties file:
      Code:
      myProperty=3

      Comment

      Working...
      X