【ssm中读取配置文件(resource.properties)的方法】

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;
}

这样在这个类中就可以使用该属性了!!!

 

posted @ 2017-06-01 21:30  半生戎马,共话桑麻、  阅读(3287)  评论(0)    收藏  举报
levels of contents