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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:44:58+00:00 2026-06-17T23:44:58+00:00

Before post this Question, I google to get Properties from Spring project(Its NOT web-based

  • 0

Before post this Question, I google to get Properties from Spring project(Its NOT web-based project). I am confused as every one are talking about application-context.xml and have configuration like

However, I am working on normal Java Project with Spring(NO Web-app and stuff like that). But I would like to get some common properties from properties file and that needs to be used in JAVA file. How can achieve this by using Spring/Spring Annotations?

Where I should configure myprops.properties file under my project and how to invoke through spring?

My understanding is application-context.xml is used ONLY for web based projects. If not, how should I configure this application-context.xml as I do NOT have web.xml to define the application-context.xml

  • 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-17T23:44:59+00:00Added an answer on June 17, 2026 at 11:44 pm

    You can create an XML based application context like:

    ApplicationContext ctx = new ClassPathXmlApplicationContext("conf/appContext.xml");
    

    if the xml file is located on your class path. Alternatively, you can use a file on the file system:

    ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/appContext.xml");
    

    More information is available in the Spring reference docs. You should also register a shutdown hook to ensure graceful shutdown:

     ctx.registerShutdownHook();
    

    Next, you can use the PropertyPlaceHolderConfigurer to extract the properties from a ‘.properties’ file and inject them into your beans:

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations" value="classpath:com/foo/jdbc.properties"/>
    </bean>
    
    <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    

    Lastly, if you prefer annotation based config, you can use the @Value annotation to inject properties into you beans:

    @Component
    public class SomeBean {
    
        @Value("${jdbc.url}") 
        private String jdbcUrl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sorry to post question hich was here before, but this is driving
Before I get anywhere with this post, let me make this clear, there is
Before answering this question, understand that I am not asking how to create my
I think probably this question has been asked/answered several times before my post. But
I realize this question has been asked before, but I can't get it to
Before I post this question, I found somehow similar question posted here . But
Before post my question here,i tried google it and followed different way they suggested
I have set a property across threads before and I found this post Cross-thread
This is my first post. I know this topic has been discussed before in
Before, I post a question here asking for advice on how to read and

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.