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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:58:44+00:00 2026-06-08T18:58:44+00:00

I tried following in spring: modules.xml : <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd> <import resource=classpath:module1.xml></import>

  • 0

I tried following in spring:

modules.xml:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <import resource="classpath:module1.xml"></import>
    <import resource="classpath:module2.xml"></import>
</beans>

module1.xml:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

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


    <bean id="bean1" class="Bean1">
        <property name="prop1" value="${key}"/>
    </bean>
</beans>

module2.xml:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

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

    <bean id="bean2" class="Bean2">
        <property name="prop2" value="${key}"/>
    </bean>
</beans>

Bean1.java:

import org.springframework.beans.factory.annotation.Autowired;

public class Bean1 {

    @Autowired
    public String prop1;

    public void setProp1(String val) {
        prop1 = val;
    }
}

bean2.java:

import org.springframework.beans.factory.annotation.Autowired;

public class Bean2 {
    @Autowired
    public String prop2;

    public void setProp2(String val) {
        prop2 = val;
    }
}

ModulesBean.java:

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ModulesBean {
    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
                new String[] {"modules.xml"});
        BeanFactory beanFactory = (BeanFactory) appContext;

        Bean1 bean1 = (Bean1) beanFactory.getBean("bean1");
        System.out.println("prop1: " + bean1.prop1);

        Bean2 bean2 = (Bean2) beanFactory.getBean("bean2");
        System.out.println("prop2: " + bean2.prop2);

    }
}

prop1.properties:

key=value1

prop2.properties:

key=value2

When I run it, the result is this:

prop1: value1
prop2: value1

However I want to have scope for bean1 to take only props from props file 1!!! As it’s a module and other Bean2 to take value2!!!

Is that achievable? I find it so very basic! Thanks!!!

Important: it is important to me that I have an XML which includes the submodules! In this way I utilize springs nicely XML which there I define which beans I have as submodules (useful for other things for me as well). Also they live of course in same context! Very important for me that beans are in same context.

important: modules are written by other developers, I have no way to control which property names they use.

important: parent module must be able to run the child modules beans which means parent/child is not good here, also child modules need not be aware of parent properties because they are just modules.

  • 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-08T18:58:46+00:00Added an answer on June 8, 2026 at 6:58 pm

    Consider using Parent/Children Spring context hierarchy. For example, you can create a parent context and two children contexts, load your property files in an appropriate one. Beans which were loaded in the parent one are shared between all children contexts, but children contexts has their own scope for beans.

    You can find more information on the Internet.

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

Sidebar

Related Questions

I tried following the following example to make an HTTP link in my TextView
I'm investigating an annotation-based approach to validating Spring beans using spring modules . In
I'm following Ruby on Rails Tutorial: Learn Rails by Example, by Michael Hartl. http://ruby.railstutorial.org/chapters/a-demo-app#sec:a_micropost_microtour
I have tried to use the following snippet of code: int main() { string
Tried following the instructions here: How to use Google app engine with my own
I tried following the instruction s but can't get the plugin to work, the
I tried following the gradle manual with their example like this but copyJars is
I tried following the answer here how to override a task making it depend
I tried following the answer to this question , but could not get xsd.exe
I tried following the README file in Ruby 1.9.1 but I can't compile it

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.