在bean(可是controller, service, dao等了)中,使用@Value注解:
在spring中定义资源文件:@Service
public class TestService{
@Value("${sytem.username}") String loginUserName;
}
<context:property-placeholder />或者org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<array>
<value>classpath:config.properties</value>
</array>
</property>
</bean>
config.properties文件:
这样config.properties中的 sytem.username就注入到 loginUserName属性中了sytem.username=admin