通過@value讀取properties注意點
-
applicationContext檔案讀取檔案需要配置成為多檔案讀取方式
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <!-- jdbc配置 --> <value>classpath:config/jdbc.properties</value> <!-- 通用配置 --> <value>classpath:config/appConfig.properties</value> </list> </property> </bean> 複製程式碼
-
需要將java配置到service.impl中,就是需要spring service層級能夠掃描到
@Component("commonConfig") public class CommonConfig { @Value("${config.isaKey}") private String isaKey; @Value("${config.doubankey}") private String doubanKey; @Value("${config.juheKey}") private String juheKey; @Value("${config.oneUuid}") private String oneUuid; public String getIsaKey() { return isaKey; } public String getDoubanKey() { return doubanKey; } public String getJuheKey() { return juheKey; } public String getOneUuid() { return oneUuid; } } 複製程式碼