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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:19:31+00:00 2026-05-27T15:19:31+00:00

My servlet.xml file holds all my spring configuration related information like datasource bean etc.

  • 0

My servlet.xml file holds all my spring configuration related information like datasource bean etc.

<bean id="..." class="...">
</bean>

Now my application has other settings that I need to save in a configuration file, is it possible to create my own settings in here or is there a better way?

I want something that loads up once and is very fast to reference in my project.

I need this to store some file paths, and other database settings for things like mongodb etc.

  • 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-27T15:19:32+00:00Added an answer on May 27, 2026 at 3:19 pm

    You can use .properties file:

    <context:property-placeholder location="file:///my/cfg.properties"/>
    

    If the file contents are:

    driver=com.mysql.jdbc.Driver
    dbname=mysql:mydb
    mysetting=42
    

    You can reference them in Spring XML like this:

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
     <property name="driverClassName"><value>${driver}</value></property>
     <property name="url"><value>jdbc:${dbname}</value></property>
    </bean>
    

    Reference: 4.8.2.1 Example: the PropertyPlaceholderConfigurer.

    You can also inject these properties into your own classes:

    @Service
    public class MyService {
        @Value("${mysetting}")
        private int mysetting;  //Spring will inject '42' on bean creation
    
        //...
    }
    

    Of course you can also use setter-injection like in the example with DriverManagerDataSource if you prefer XML.

    Also have a look at: Spring 3.1 M1: Unified Property Management.

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

Sidebar

Related Questions

I am separating my spring bean configuration files as follows: myapp-service.xml myapp-servlet.xml However I
In my spring-servlet.xml I have <bean id=messageSource class=org.springframework.context.support.ReloadableResourceBundleMessageSource> <property name=basename value=/WEB-INF/messages /> </bean> My
spring-servlet.xml setting up theme beans: <bean id=themeSource class=org.springframework.ui.context.support.ResourceBundleThemeSource> <property name=basenamePrefix value=theme- /> // also
Say in my web.xml file, I define a servlet like so: <url-pattern>/MyURL/*</url-pattern> How do
is springdoclet use to generate bean defination xml files? servlet-config.xml..etc ? i trying to
In a spring servlet xml file, I'm using org.springframework.scheduling.quartz.SchedulerFactoryBean to regularly fire a set
How to determine what xmlns are required for beans component of my spring-servlet.xml(spring configuration
i'm using Spring-WS and have the following spring-ws-servlet.xml file. The injection of defaultURI and
I have a datasource set in my Jetty.xml file that looks like this: <New
i'm writing a servlet that receives a xml file, gives it to another class

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.