In a SPRINGMVC project, you get the configuration in the properties configuration file by annotating @value, using the package that the annotation must introduce:
Spring-beans-4.1.4.release.jar
Here's what you need to configure in spring's configuration file
<?xml version= "1.0" encoding= "UTF-8"?><Beans xmlns="Http://www.springframework.org/schema/beans" Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance" Xmlns:context="Http://www.springframework.org/schema/context" Xmlns:tx="Http://www.springframework.org/schema/tx" XMLNS:AOP="HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX http://www.springframework.org/schema/tx/spring-tx-3.0.xsd/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd " > <bean id= "configproperties" class=" Org.springframework.beans.factory.config.PropertiesFactoryBean "> < property name="Locations"> <list> <value>Classpath*:config/autocreatetable.properties</value> </list> </Property > </Bean> <bean id= "propertyconfigurer" class=" Org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer "> < property name="Properties" ref="Configproperties" / > </Bean></Beans>
After configuring the above configuration, you can take this in your code:
/** * 要扫描的model所在的pack */ @Value("#{configProperties[‘mybatis.model.pack‘]}") private String pack; /** * 自动创建模式:update表示更新,create表示删除原表重新创建 */ @Value("#{configProperties[‘mybatis.table.auto‘]}") private String tableAuto;
Configproperties is the value in the Bean's id,["] is the key in the configuration file to be taken, so that the value in the configuration file can be mapped to the pack, Tableauto attribute in the code.
Get Properties profile by annotations in SPRINGMVC