2012-06-29 18 views

回答

3

是隻使用它們注入@Value annoation,如:

@Service("myService") 
public class MyService 

    @Value("${myProperty}") 
    String whatever; 
... 

,然後在應用方面:

<context:property-placeholder 
    location="classpath:application.properties" 
    ignore-unresolvable="true" 
/> 

包含您的字符串棒文件application.properties瓦爾在classpath中(通過SRC正常/主/資源)。

或者您也可以確保您的文件是在類路徑和參考,作爲類路徑資源

final org.springframework.core.io.Resource myFile = new ClassPathResource("MyTextFile.text"); 
相關問題