У меня есть файл свойств report.properties (\ WEB-INF \ Classes \ свойства \ report.properties) с входа:использованием @value с PropertyPlaceholderConfigurer
reportTemplate = reports/report5.jrxml
и ApplicationContext-reports.xml (\ WEB-INF \ Config \ ApplicationContext-reports.xml) с вхождением:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:properties/report.properties"/>
</bean>
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext-reports.xml
</param-value>
</context-param>
В мой контроллер у меня есть:
private @Value("${reportTemplate}") String reportTemplatePath;
Но когда я напечатать это, чтобы проверить его значение как:
System.out.println("reportTemplatePath="+reportTemplatePath);
Вместо выхода: reports/report5.jrxml
(из файла свойств) дает reportTemplatePath=${reportTemplate}
Редактировать: Скопированный комментарий ОП здесь для ясности и показать, где находится System.out.println
.
@Controller
public class myController {
private @Value("${reportTemplate}") String reportTemplatePath;
// other field declarations...
@RequestMapping(value="report.htm", method=RequestMethod.GET) public String showReport() throws JRException{
...
System.out.println("reportTemplatePath="+reportTemplatePath);
...
return "report";
}
}
В какой момент вы его печатаете? Я подозреваю, что printlning происходит до введения '@ Value'. Попробуйте добавить метод '' @ PostConstruct' (http://docs.oracle.com/javase/6/docs/api/javax/annotation/PostConstruct.html) и вывести там приватное поле или получателя, которым вы можете быть вызванный после того, как класс построен и подключен. – andyb
@andyb: Nopes! Я печатаю его после объявления @Value как: '@Controller public class myController { private @Value (" $ {reportTemplate} ") String reportTemplatePath; // другие полевые декларации ... \t @RequestMapping (значение = "report.htm", метод = RequestMethod.GET) общественности Строка ShowReport() броски JRException { ... \t \t \t \t системы. out.println ("reportTemplatePath =" + reportTemplatePath); \t \t \t \t ... \t \t \t \t возвращение "отчет"; } } ' –