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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:08:37+00:00 2026-05-23T01:08:37+00:00

I have a web application that use Sring IoC framework. I use the Java

  • 0

I have a web application that use Sring IoC framework.
I use the Java configuration for Spring, and I only use @Configuration annoted module definition (no DI related tags elsewhere in the code).

The Spring registry is built on web application start-up thanks to (a bit modified version of) Spring context loader listener, and the contextConfigLocation param in web.xml configured to point to the @Configuration annotated class.

All that is good and I get a AnnotationConfigWebApplicationContext.

Now, I want to have plugins in my application, that will have their own @Configuration annotated configuration classes, and will use some of the main application services. BUT I don’t want to have main application to be modified to load these new modules.

So, I thought that I could simply use the package searching of annotated class for that, but now, it seems that I can use two beans with the same type, even if they have different ids, and clearly AnnotationConfigWebApplicationContext doc states that:

Note: In case of multiple @Configuration classes, later @Bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra Configuration class.

I don’t want that, because modules should be able to contribute alternative version of services, not (alwways) override existing one – especcially if I want to have a “moduleDef” bean.

I tried to use differents approach on that, but the hierachy of Context and related services is just to big for me.

So, does anybody know how I could reach my goal ?

Thanks

  • 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-23T01:08:37+00:00Added an answer on May 23, 2026 at 1:08 am

    You can have multiple beans of the same type, but You cannot have 2 or more beans with the same ID in a single Spring ApplicationContext – no matter if You use XML or JavaConfig.

    The overriding mechanism matches the bean ID’s, so all You need to do is to ensure unique ID, i.e.: coreModuleDef, someOtherModuleDef, anotherModuleDef. I don’t think You need the ID of each module definition to be identical? What should be sufficient is the type to be the same, but not ID.

    You can also turn off the overriding mechanism by setting allowBeanDefinitionOverriding to false on Your AnnotationConfigWebApplicationContext to get an exception if You accidentally override a bean:

    public class MyDispatcherServlet extends DispatcherServlet {
        @Override
        protected void postProcessWebApplicationContext(
                ConfigurableWebApplicationContext wac) {
    
            ((AnnotationConfigWebApplicationContext) wac)
                .setAllowBeanDefinitionOverriding(false);
        }
    }
    

    or:

    public class MyContextLoaderListener extends ContextLoaderListener {
        @Override
        protected void customizeContext(
                ServletContext servletContext,
                ConfigurableWebApplicationContext applicationContext) {
    
            ((AnnotationConfigWebApplicationContext) wac)
                .setAllowBeanDefinitionOverriding(false);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that makes use of a Spring TaskExecutor. The task
I have a web application that makes heavy use of the Session state to
Suppose you have two seperate ASP.NET Web Application projects that both need to use
I have a web application based on the sharp-architecture framework. It actually use NHibernate
So I have a .net web application that I use the VS 2010 publish
I have a web application that uses Struts2 + Spring for the resource injection,
I have a web application that should behave differently for internal users than external
I have a web application that is becoming rather large. I want to separate
I have a web application that needs to take a file upload from the
I have this web application that has grown to an unmanageable mess. I want

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.