У меня есть файл свойств с именем 'registrows.properties'.
Я настроил в applicationContext.xml свойство-заполнитель:
<context:property-placeholder location="classpath:registrows.properties" />
Я настроил вweb.xml a "ContextLoaderListener":
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Я хотел бы получить доступ к значениям этих свойств в методе сервлета init.Я пробовал с аннотацией @Value, но она не работает:
public class MyServlet extends HttpServlet
{
@Value( "${app1.myproperty}" )
private String myProperty;
public MyServlet ()
{
super();
}
@Override
public void init(ServletConfig config) throws ServletException
{
super.init(config);
System.out.println(myProperty);
}
public void setMyProperty (String value)
{
this.myProperty = value;
}
public String getMyProperty ()
{
return this.myProperty;
}
}
Как я могу это сделать?
Я использую spring-mvc 5.0.4.
Спасибо