Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:34:03+00:00 2026-06-09T18:34:03+00:00

As explained here and here it is quite clear how to do it but

  • 0

As explained here and here it is quite clear how to do it but still can’t seem to make it work.
I simply like to use the @Value annotation in order to inject a property to a spring bean. I created a basic spring MVC project with one controller and one bean.

Here is my application context:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
   http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">


<!-- Root Context: defines shared resources visible to all other web components -->

<context:component-scan base-package="me.co.fatsecret" />

<!-- Properties -->

<bean id="props"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:fatProperties.properties" />
</bean>


</beans>

I have one bean called Configuration:

package me.co.fatsecret;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Configuration {

    /*--- Members ---*/

    @Value("${api_key}")
    protected String API_KEY;
    @Value("${api_secret}")
    protected String API_SECRET;
    @Value("${api_url}")
    protected String API_URL;

    /*--- Constructors ---*/

    public Configuration() {
    }

    /*--- Getters & Setters ---*/

    public String getAPI_KEY() {
    return API_KEY;
    }

    public void setAPI_KEY(String aPI_KEY) {
    API_KEY = aPI_KEY;
    }

    public String getAPI_SECRET() {
    return API_SECRET;
    }

    public void setAPI_SECRET(String aPI_SECRET) {
    API_SECRET = aPI_SECRET;
    }

    public String getAPI_URL() {
    return API_URL;
    }

    public void setAPI_URL(String aPI_URL) {
    API_URL = aPI_URL;
    }

}

Now I have only one controller, injected with this Configuration class and as I call this controller I see that the values in the Configuration class are not populated right.

My properties file is located under the resources folder (src/main/resources) and is a part of my classpath (done by default since this is a maven project). Here it is:

api_url=http://platform.fatsecret.com/js?
api_key=SomeKey
api_secret=SomeSecret

The file name is fatProperties.properties.
As I debug my server when calling the controller I see that the content of the Configuration class is:

${api_key}
${api_secret}
${api_url}

This is the actual value of the Strings, wich means that the vales from the properties file are not getting injected for some reason.

Am I missing something here?

UPDATE1: I replaced the PropertyPlaceholderConfigurer bean with:

<context:property-placeholder location="classpath:fatProperties.properties"/>

Getting the same result

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:34:05+00:00Added an answer on June 9, 2026 at 6:34 pm

    Ok, got it!

    I’m using a spring MVC project, which means I have a separated context for my web layer (the controllers). The “Configuration” bean which hods the properties using the @Value annotation is injected to a controller. My property-placeholder is defined within my root-context hence it cannot be seen from my controller. To resolve the issue I simply added the property-placeholder definition to my DispatcherServlet context and it works like a charm 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As explained here , Math.Ceiling returns: The smallest integral value that is greater than
I want to make a gui for what i explained here C# visual control
As seen here and some other places for each is well explained, but how
I've posted similar question here , but it was closed because I didn't explained
I’m a long time listener, but first time caller here… Hoping you can help
Not quite sure how to explain this but here goes. I have a function
Quite a while ago Ryan Weaver explained to me on Stack how to use
quite a newbie here but here's a small test code that explains my issue.
Quite new to maven here so let me explain first what I am trying
I'm trying to add a Search-ActionView to my application (as explained here http://developer.android.com/guide/topics/search/search-dialog.html#UsingSearchWidget ).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.