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

1
  • 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. Commented Nov 5, 2015 at 12:46

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.