Only the exception point, about how to configure the file, here do not explain. 1. The controller cannot read the Config.properties file the @value configuration injected in the controller is obtained from the servlet-context.xml configuration file; The value configuration can be obtained from the applicationcontext.xml. Therefore, if you want to inject the property configuration into the controller, you need to add the configuration to the corresponding servlet file, as in Applicationcontext.xml.
class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property Name= "Locations" > <list> <value>classpath:jdbc.properties</value> <value >classpath:config.properties</value> </list> </property> <property name= " Ignoreunresolvableplaceholders "value=" true "/></bean>
The Config.properties file cannot be read in 2.service to see if the configuration file has more than one. If the configured path is classpath:config.properties, mouse click on the file. If "Multiple implementations" is displayed, indicating that there are multiple files, to see if there are any required configuration items in the other files, it is possible that the configuration item that loaded the other file is not available. At this point, change the path to classpath*:config.properties.
<context:property-placeholder ignore-unresolvable= "true" location= "classpath:/jdbc.properties, Classpath*:/config.properties "/>
View the log and discover:
[2017-01-05 16:45:02 INFO] [Main] (org.springframework.context.support.PropertySourcesPlaceholderConfigurer:?) -Loading properties file from URL [jar:file:/home/admin/creative-task/lib/xxxx-common-1.5.7.jar!/ config.properties][2017-01-05 16:45:02 INFO] [main] ( Org.springframework.context.support.PropertySourcesPlaceholderConfigurer:?) -Loading properties file from URL [file:/home/admin/creative-task/conf/config.properties]
Two config.properties files were loaded.
3. About Diagnostics: 1) First verify that the configuration file is loaded correctly. View log: The normal log is as follows:
[2017-01-05 16:45:02 INFO] [Main] (org.springframework.context.support.PropertySourcesPlaceholderConfigurer:?) -Loading properties file from URL [file:/home/admin/creative-task/conf/config.properties]
The Exception log is as follows:
ClassClass path resource [config.properties] cannot be opened because it does not exist
If the file is not loaded, see if the path matches, and so on. 2) If the file loads OK, check that the configuration properties are loaded correctly. To view the debug logs for Tomcat startup: The normal log is as follows:
[2017-01-05 16:45:04 DEBUG] [Main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) -Searching forKey ' Adx.id 'In [environmentproperties][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Searching forKey ' Adx.id 'In [systemproperties][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Searching forKey ' Adx.id 'In [systemenvironment][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Could not find key ' Adx.id ' in any property source. returning [NULL][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Searching forKey ' Adx.id 'In [localproperties][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Found key ' adx.id ' in [localproperties] with type [String] and value ' 1 '
The Exception log is as follows:
[2017-01-05 16:34:01 DEBUG] [Main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) -Searching forKey ' Adx.id 'In [environmentproperties][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Searching forKey ' Adx.id 'In [systemproperties][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Searching forKey ' Adx.id 'In [systemenvironment][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Could not find key ' Adx.id ' in any property source. returning [NULL][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Searching forKey ' Adx.id 'In [localproperties][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?)-Could not find key ' Adx.id ' in any property source. returning [NULL]
If the configuration property is not loaded correctly, see if the key for the property configuration is correct.
Spring cannot read properties file data