spring讀取配置文件內容並自動註入
阿新 • • 發佈:2019-01-21
多個 con 自動註入 分頁 frame 讀取 text oid ole
添加註解:
@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
spring讀取配置文件內容並自動註入