1. Configuration files (*.properties) are often registered with the spring IOC in the following ways.
<!--JDBC Configuration - <Context:property-placeholder Location= "Classpath:mybatis/db.properties"ignore-unresolvable= "true" /> <!--Public number Information - <Context:property-placeholder Location= "Classpath:wechat/official-account.properties"ignore-unresolvable= "true" /> <!--Trigger Expression - <Context:property-placeholder Location= "Classpath:wechat/cron-expression.properties"ignore-unresolvable= "true" /> <!--other configurations (paging size, frequency of access, etc.) - <Context:property-placeholder Location= "Classpath:wechat/other.properties"ignore-unresolvable= "true" />
2. In the class of the control layer or business layer, one of the properties is introduced through @Value annotations.
/src/main/resources/mybatis/db.properties
# Db.propertiesjdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/demo ? characterencoding=utf-8&useunicode=true&usessl=false&allowmultiqueries=trueJdbc.username= Rootjdbc.password=root
Io.spldeolin.demo.controller.OneController
@Controller Public class { @Value ("${jdbc.password}") private String A; // Others Ignore }
DEBUG
Read the properties file in spring