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

  • Home
  • SEARCH
  • 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 3808814
In Process

The Archive Base Latest Questions

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

I have a beans.xml file for an LDAP application that I am writing. I

  • 0

I have a beans.xml file for an LDAP application that I am writing. I am allowing the user the choice of several LdapContextSource(s). For each one I have a different bean, e.g.

<bean id="ldapTemplate" class="yyy.LdapTemplate">
      <constructor-arg ref="contextSource1" />
</bean>
<bean id="contextSource1" class="xxx.LdapContextSource">
      ...
</bean>
<bean id="contextSource2" class="xxx.LdapContextSource">
      ...
</bean>
<bean id="contextSource3" class="xxx.LdapContextSource">
      ...
</bean>

You can see that only one of these context source beans gets instantiated, because only one is referred to by the ldapTemplate bean. However, when I run my application, my Spring log messages in stdout provide information about each context source, even though only one is depended on.

Jan 25, 2011 11:56:36 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
INFO: Property ‘userDn’ not set – anonymous context will be used for read-write operations
Jan 25, 2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
INFO: Property ‘userDn’ not set – anonymous context will be used for read-write operations
Jan 25, 2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
INFO: Property ‘userDn’ not set – anonymous context will be used for read-write operations

My questions are:

(1) What is Spring doing with the context sources that are not referred to / depended on? They should never be instantiated in my application, and it worries me that Spring is providing log information for each of these beans.

(2) Should I comment out the context source beans that are not used in the application? What are the consequences of leaving them uncommented? What is the standard practice?

Thanks,
ktm

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

    Maybe you could check out Lazy Loading of Beans. Here is the relevant explanation from the Spring 2.5.x docs…

    The default behavior for
    ApplicationContext implementations is
    to eagerly pre-instantiate all
    singleton beans at startup.
    Pre-instantiation means that an
    ApplicationContext will eagerly create
    and configure all of its singleton
    beans as part of its initialization
    process. Generally this is a good
    thing, because it means that any
    errors in the configuration or in the
    surrounding environment will be
    discovered immediately (as opposed to
    possibly hours or even days down the
    line).

    However, there are times when this
    behavior is not what is wanted. If you
    do not want a singleton bean to be
    pre-instantiated when using an
    ApplicationContext, you can
    selectively control this by marking a
    bean definition as lazy-initialized
    . A
    lazily-initialized bean indicates to
    the IoC container whether or not a
    bean instance should be created at
    startup or when it is first requested.

    For the sake of completness here is an example…

    <bean id="contextSource1" class="xxx.LdapContextSource" lazy-init="true"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The basic problem I have here is that I have one xml file that
i want to have a xml file in the user specifed directory. for that
I have a java application that use spring with a spring.xml file in the
I have many cookie-cutter spring beans and don't want to explicitly define each one
I have a large application that uses EJB 2.x entity beans (BMP). This is
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I have simple application with following folder structure: ProjFolder |-----src |----------packagename |---------------{sourcefiles} |----------META-INF |---------------{beans.xml}
I have a ConfigParameter SLSB that reads configuration values from the ejb-jar.xml file. This
I have a simple Spring MVC application that looks up some user details from
I have a FileSystemXmlApplicationContext and I would like the beans defined in the XML

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.