我使用屬性在Spring框架文件屬性不是從屬性中找到文件中使用@Value
根的context.xml
<context:property-placeholder location="classpath:config.properties" />
<util:properties id="config" location="classpath:config.properties" />
Java代碼
@Value("#{config[ebookUseYN]}")
String EBOOKUSEYN;
使用URL調用(當@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();
}
}
當 '這點' 方法調用,改變控制器和不讀屬性文件場..
@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
你確定你的屬性文件包含一個'IndexBasePath'條目並且它寫在你的代碼中嗎?請注意,條目名稱應該按原樣書寫,因爲Spring將解析這個區分大小寫。 –
當然。 'IndexBasePath = D:\\ BTBF_Index \\'條目是在屬性文件..和其他情況下使用此條目..但這種情況下不工作.. – HoHoHo