Announcement Announcement Module
Collapse
No announcement yet.
PropertiesLoaderSupport, ignoreResourceNotFound, and warning message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertiesLoaderSupport, ignoreResourceNotFound, and warning message

    When loading properties, PropertiesLoaderSupport class logs a warning message "Could not load properties from ...", even though ignoreResourceNotFound is explicitly configured to true. IMO warning level is too much, info would be more appropriate because ignoreResourceNotFound defaults to false, and one has to deliberatly/consciously set it to true.

    What does Spring community and Spring committers think about this suggestion?


    Here is the relevant code from org.springframework.core.io.support.PropertiesLoad erSupport class ():

    Code:
    	protected void loadProperties(Properties props) throws IOException {
    		if (this.locations != null) {
    			for (Resource location : this.locations) {
    				if (logger.isInfoEnabled()) {
    					logger.info("Loading properties file from " + location);
    				}
    				InputStream is = null;
    				try {
    					is = location.getInputStream();
    
    					String filename = null;
    					try {
    						filename = location.getFilename();
    					} catch (IllegalStateException ex) {
    						// resource is not file-based. See SPR-7552.
    					}
    
    					if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
    						this.propertiesPersister.loadFromXml(props, is);
    					}
    					else {
    						if (this.fileEncoding != null) {
    							this.propertiesPersister.load(props, new InputStreamReader(is, this.fileEncoding));
    						}
    						else {
    							this.propertiesPersister.load(props, is);
    						}
    					}
    				}
    				catch (IOException ex) {
    					if (this.ignoreResourceNotFound) {
    						if (logger.isWarnEnabled()) {
    							logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
    						}
    					}
    					else {
    						throw ex;
    					}
    				}
    				finally {
    					if (is != null) {
    						is.close();
    					}
    				}
    			}
    		}
    	}

  • #2
    This is a very annoying feature of Spring PropertyOverrideConfigurer.

    I agree that when ignore is set to false it should log a WARN or ERROR. But when it is set to true it should be no higher than DEBUG!

    Here is an example to demonstrate why:

    - The PropertyOverrideConfigurer allows you to create a DEV and a PROD properties file, so that you have a single context that doesn't have to be modified as you move betwen contexts.
    - The PROD properties file is loaded first, then the DEV one. That ensures that when you check the project out of version control you get both files, but since DEV is last... it runs as DEV when you check it out.
    - Then, when you deploy to PROD... you simply delete the DEV properties file.

    In this scenario you minimize human error, excessive manual work, but... you get the stupid WARN.

    The only way to avoid the WARN is to set the logging to ERROR, which should not be necessary.

    Comment

    Working...
    X