@value
At this stage I think everyone is not unfamiliar with annotations, @value usage is to get the configuration file information in the background, so as to facilitate the modification of some fixed configuration. Do not understand the @value Baidu can be detailed.
There are several steps to configuring the @value.
1, first create a new configuration file, System.properties
Directory structure such as
The contents are as follows
Jdbc.jdbcurl=jdbc:mysql://localhost:3306/commentdemo?useunicode=true&characterencoding
2. Configure the XML file. Is the spring configuration file, add the following content
<!--@value Annotations -<BeanID= "Configproperties"class= "Org.springframework.beans.factory.config.PropertiesFactoryBean"> < Propertyname= "Locations"> <List> <value>Web-inf/config/system.properties</value> </List> </ Property></Bean><BeanID= "Propertyconfigurer"class= "Org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> < Propertyname= "Properties"ref= "Configproperties" /></Bean>
3. Use in Controller
@Controller @requestmapping ( "Usermanager" ) Class Usercontroller extends basecontroller{@Value ( "#{configproperties[' Jdbc.jdbcurl '}"
private
String Jdbcurl; @Resource private Userdao Userdaoimpl; @RequestMapping (Value = "/showlist" String Showlist (model model) {SYSTEM.OUT.PRINTLN (Jdbcurl); return "index"
4. See the results below
Environment configuration for @value in Java