我在spring框架中使用属性文件
根上下文.xml
<context:property-placeholder location="classpath:config.properties" />
<util:properties id="config" location="classpath:config.properties" />
爪哇代码
@Value("#{config[ebookUseYN]}")
String EBOOKUSEYN;
当使用 url call( @RequestMapping(value="/recommendbooks" , method=RequestMethod.GET, produces="application/json;charset=UTF-8")
).. 这个工作!
但是,我使用方法调用,
public void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
IndexManageController indexManage = new IndexManageController();
CommonSearchDTO commonSearchDTO = new CommonSearchDTO();
try {
if("Y".equals(EBOOKUSEYN)){
indexManage.deleteLuceneDocEbook();
indexManage.initialBatchEbook(null, commonSearchDTO);
}
indexManage.deleteLuceneDoc(); <= this point
indexManage.deleteLuceneDocFacet();
indexManage.initialBatch(null, commonSearchDTO);
}catch (Exception e) {
e.printStackTrace();
}
}
当 'this point' 方法调用时,更改控制器,并且不读取属性文件字段..
@Value("#{config[IndexBasePath]}")
String IndexBasePath;
@RequestMapping(value="/deleteLuceneDoc" , method=RequestMethod.GET, produces="application/json;charset=UTF-8")
public @ResponseBody ResultCodeMessageDTO deleteLuceneDoc()
throws Exception
{
long startTime = System.currentTimeMillis();
ResultCodeMessageDTO result = new ResultCodeMessageDTO();
System.out.println(IndexBasePath);
}
它不读IndexBasePath