在spring配置文件中加入一个bean
其中location属性为properties配置文件名称(需要放在/src/main/resources路径下)
fileEncoding属性为properties文件的编码格式
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="staticConfig.properties" />
<property name="fileEncoding" value="GBK"></property>
</bean>
在需要注入的类中添加属性和get/set方法接收
在spring配置文件使用property 标签搭配${}进行注入
private String staticConfig;
public String getStaticConfig() {
return staticConfig;
}
public void setStaticConfig(String staticConfig) {
this.staticConfig = staticConfig;
}
@Override
public String getServiceName() {
return "ssn54Service";
}
<bean parent="AbstractModelServiceImpl" class="com.msh.ssn.service.impl.SSN54ServiceImpl">
<property name="staticConfig" value="${exam.voiceurl}"></property>
</bean>
staticConfig.properties 内容如下
exam.voiceurl=C:\\Users\\Administrator\\Desktop\\考试须知.wav