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 9188511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:01:33+00:00 2026-06-17T20:01:33+00:00

Using the new @PropertySource annotation in Spring 3.1, how can you access multiple property

  • 0

Using the new @PropertySource annotation in Spring 3.1, how can you access multiple property files with Environment?

Currently I have:

@Controller
@Configuration 
@PropertySource(
    name = "props",
    value = { "classpath:File1.properties", "classpath:File2.properties" })
public class TestDetailsController {


@Autowired
private Environment env;
/**
 * Simply selects the home view to render by returning its name.
 */
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {

    String file1Name = env.getProperty("file1.name","file1.name not found");
            String file2Name = env.getProperty("file2.name","file2.name not found");

            System.out.println("file 1: " + file1Name);
            System.out.println("file 2: " + file2Name);

    return "home";
}

The result is the correct file name from File1.properties, but file2.name not found. How can access File2.properties?

  • 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-17T20:01:34+00:00Added an answer on June 17, 2026 at 8:01 pm

    there are two different approaches:
    the first one is to use the PropertyPlaceHolder in your applicationContext.xml:
    beans-factory-placeholderconfigurer

    <context:property-placeholder location="classpath*:META-INF/spring/properties/*.properties"/>
    

    the namespace to add is xmlns:context="http://www.springframework.org/schema/context"

    If you want a direct access of a key to a String variable in your controller, use:

    @Value("${some.key}")
    private String valueOfThatKey;
    

    The second approach is to use the util:properties in you applicationContext.xml:

    <util:properties id="fileA" location="classpath:META-INF/properties/a.properties"/>
    <util:properties id="fileB" location="classpath:META-INF/properties/b.properties"/>
    

    using the namesapce xmlns:util="http://www.springframework.org/schema/util" schemaLocations: http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd

    Then in your Controller:

    @Resource(name="fileA")
    private Properties propertyA;
    
    @Resource(name="fileB")
    private Properties propertyB;
    

    If you want a value from the files, just use the method getProperty(String key)

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

Sidebar

Related Questions

Can I call constructor explicitly, without using new , if I already have a
When you allocate an array using new [] , why can't you find out
I'm getting an access violation on a char array I just created using new
I am using New-Object System.Management.Automation.PipelineStoppedException To stop the pipeline OK..works.. But how Can I
In C#, I can write something like: using (new MyDisposableClass().MethodA()); The semicolon causes a
I have three methods: public void Save<T>(T entity) { using (new Transaction()) { Session.Save(entity);
In java String can be created by using new operator or by using +
I created a CultureInfo object using new CultureInfo(fr-FR). Now I have a number that
Currently I’m having some difficulties with using new Magento's soap v2 from c# interface.
I have this test in my test base: public void WorksWithAreaUsers() { using (new

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.