0

I have defined the context params in web.xml

<context-param>
        <param-name>apikey</param-name>
        <param-value>45370652</param-value>
    </context-param>
    <context-param>
        <param-name>secretkey</param-name>
        <param-value>3eada72ef0ae12e15b138ae098c268c087f08ca8</param-value>
    </context-param>
</web-app>

I have enabled @Component and @Value annotations in Class and field levels in the bean class. But, it doesn't seem to read them. It is always null

@Component public class TokBoxSettings {

@Value("${apikey}")
private  String apikey; 

@Value("${secretkey}")
private  String secretkey; 

I have also added the below bean mapping to spring-servlet.xml for configuring PropertyPlaceholder

<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>

Please let me know what i have missed

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
  • Generally bean definition and settings are contained in `@Configuration` annotated classes. Did you try changing `@Component` to `@Configuration` for `TokBoxSettings`? Those two stereotypes may differ in ordering. – px5x2 Nov 05 '15 at 12:46

2 Answers2

1

I am junior spring + hibernate developer,I have one alternative solution for this question,may be you know

I used bean name and its property to set direct context-param value

<bean ...>
   <property name="apikey" value="${apikey}" />
</bean>
sanjay
  • 437
  • 3
  • 17
1

Set property ignoreUnresolvablePlaceholders to true inside bean declaration. i.e. add below tags in spring-servlet.xml

<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

Its worked for me.

Varun
  • 99
  • 2
  • 10