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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:13:30+00:00 2026-05-30T05:13:30+00:00

I my application I have an application-context.xml. Now I am instantiating The ApplicationContext as:

  • 0

I my application I have an application-context.xml. Now I am instantiating The ApplicationContext as:

ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");

Is it possible to pass parameter through this instantiation so that those parameters could be used to initialize some properties of some beans?

PS: Not using property file. As the parameters are generated run time, like exicutable jar’s location, system architecture, os name etc which is variable.

  • 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-30T05:13:32+00:00Added an answer on May 30, 2026 at 5:13 am

    Here is the solution, I am posting it, might be helpful to someone in future:

    The Bean class:

    public class RunManager {
    
        private String jarPath;
        private String osName;
        private String architecture;
    
        public RunManager() {
    
        }
    
        public RunManager(String[] args) {
            this.jarPath = args[0];
            this.osName = args[1];
            this.architecture = args[2];
        }
    
        public String getJarPath() {
            return jarPath;
        }
    
        public void setJarPath(String jarPath) {
            this.jarPath = jarPath;
        }
    
        public String getOsName() {
            return osName;
        }
    
        public void setOsName(String osName) {
            this.osName = osName;
        }
    
        public String getArchitecture() {
            return architecture;
        }
    
        public void setArchitecture(String architecture) {
            this.architecture = architecture;
        }       
    }
    

    The initialization of the ApplicationContext:

    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(RunManager.class).addConstructorArgValue(args).getBeanDefinition();
    beanFactory.registerBeanDefinition("runManager", beanDefinition);
    GenericApplicationContext genericApplicationContext = new GenericApplicationContext(beanFactory);
    genericApplicationContext.refresh();
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] { "application-context.xml" }, genericApplicationContext);      
    

    The injection of this bean reference to another bean of application-context.xml:

    <bean id="configuration" class="jym.tan.movielibrary.configuration.Configuration" >     
        <property name="runManager" ref="runManager" />
    </bean>
    

    Thanks.

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

Sidebar

Related Questions

I have working web-application with applicationContext.xml in WEB-INF/config/applicationContext.xml. Now i need to implement some
I have now ear |----test.jar |-------META-INF |-------application.xml |-------test |-------Test.class |-------TestEJB.class |-------TestHome.class |----test.war |-------WEB-INF |-------web.xml
I have a Silverlight application that reads its content from an XML file. The
I have a winforms application that presently ships with a chm file for context-sensitive
General context : MVVM application. I have a View called JobView. Its DataContext is
In my spring application context file, I have something like: <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String"
I have a animation in my navigationbased application. [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.5]; [UIView
I have a web application, which was designed and always worked under root context
I have this Windows Forms application where it sits in the notification area. Clicking
Am trying to get the application context in my JSP page. I have the

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.