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

  • Home
  • SEARCH
  • 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 4252588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:48:55+00:00 2026-05-21T04:48:55+00:00

Is this really the easiest way how to inject a property in the controller

  • 0

Is this really the easiest way how to inject a property in the controller from properties file? It then needs to import the property file stuff on each controller which needs some properties. In a project like mine with about 30 controllers and 10 of them needing this country property it would look like mess i guess..
Did I understand the usage of @Value correctly?

@Controller
@RequestMapping(value = "/simple")
@ImportResource("classpath:/META-INF/properties-config.xml")
public class SimpleController {

    private @Value("#{exampleProperties['simple.country']}") String country;

}

properties-config.xml (skipped the xml and schema stuff)

<beans>
    <util:properties id="exampleProperties" location="classpath:/simple.properties" />
</beans>

Also when trying to import the properties-config.xml resource in more than one controller I get such messages. It just doesn’t seem the right way how to do it, but i can’t figure out a better one..

01 Apr 2011 04:52:29,859 INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory []: Overriding bean definition for bean 'exampleProperties': replacing [Generic bean: class [org.springframework.beans.factory.config.PropertiesFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.beans.factory.config.PropertiesFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
  • 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-05-21T04:48:56+00:00Added an answer on May 21, 2026 at 4:48 am

    I think your approach is overcomplicated for this case. The typical approach is to use <context:property-placeholder>. You declare

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

    in a single place, and use its properties in controllers as

    private @Value("${simple.country}") String country;
    

    Also I don’t think it’s a good idea to use @ImportResource this way, it violates Dependency Injection principle – these properties are parts of context in which your controllers are working, therefore controllers shouldn’t know how they are loaded.

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

Sidebar

Related Questions

Is this really the easiest way to do this? http://simplesamples.info/MFC/Clipboard.php
I'm having this really mind breaking problem. I created a Localizable.strings file in XCode
What's the easiest way to convert a percentage to a color ranging from Green
I'm looking for the easiest way to bind data from a SqlDataSource to textboxes
What is the easiest way to retrieve a bean id from inside that bean
Easiest way to explain what I mean is with a code sample. This doesn't
What is the easiest way to read json from Firefox or Chrome's developer console?
This really seems like a bug to me, but perhaps some databinding gurus can
This really shouldn't be hard, I just can't figure out how to do it.
This really puzzled for hours, I searched all over the internet, but got no

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.