1. 在src\main\resources\resource目錄下創建資源文件resource.properties, 在這里定義動態信息
#FTP\u76F8\u5173\u914D\u7F6E #FPT\u7684ip\u5730\u5740 FTP_ADDRESS=192.168.92.128 FTP_PORT=22 FTP_USERNAME=root FTP_PASSWORD=0000 FTP_BASE_PATH=/application/nginx-1.8.1/html/images/ TIME_OUT=1000 #\u56FE\u7247\u670D\u52A1\u5668\u7684\u76F8\u5173\u914D\u7F6E #\u56FE\u7247\u670D\u52A1\u5668\u7684\u57FA\u7840url IMAGE_BASE_URL=http://192.168.92.128/images/ REST_BASE_URL=http://localhost:8083/rest REST_CONTENT_SYNC_URL=/cache/sync/content/
2. 在配置文件applicationContext-dao.xml中把resource.properties讀進來
<!-- 加載配置文件 --> <context:property-placeholder location="classpath:resource/*.properties"/>
3. 在Service的實現類中使用注解的方式讀取資源文件信息
@Service
public class PictureServiceImpl implements PictureService{
@Value("${FTP_ADDRESS}") private String FTP_ADDRESS;
}
這樣在這個類中就可以使用該屬性了!!!