spring读取配置文件内容并自动注入
添加注解:
@PropertySource(value={"classpath:venus.properties"})
示例:
import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Service; import java.util.Map; @Service @PropertySource(value={"classpath:venus.properties"}) public class SyncService { @Value("${default.pwd}") private String defaultPwd; @Value("${default.role}") private String defaultRole; @Value("${default.area}") private String defaultArea; //venus获取用户的默认分页大小 private static int pageSize = 1000; public void venusUserSync(Map<String, Object> params) { } }
然后venus.properties中示例如下
#默认密码,登入从单点走,密码无用
default.pwd=123456
#多个角色以,隔开
default.role=1
#多个地区,隔开
default.area=350500