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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:17:38+00:00 2026-06-15T16:17:38+00:00

Let’s say I have an interface for language change event in my application (it’s

  • 0

Let’s say I have an interface for language change event in my application (it’s based on Vaadin):

public interface ILanguageChangeListener{
    @Subscribe onLanguageChange(LanguageChangeEvent event);
}

And I have many beans that implements this interface annotated with @Component, thus they are available in Spring IoC. I have also an EventBus bean:

<bean id="languageSwitcher" class="com.google.common.eventbus" scope="session" />

Now, after getting an instance of any bean from IoC I have to get also an instance of the languageSwitcher and register the newely created bean in it with:

languageSwitcher.register(myNewBean);

in order to receive this events. Is it possible to somehow tell the IoC that I want to call the register method of the languageSwitcher bean on every new bean that implements the ILanguageChangeListener?

  • 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-15T16:17:40+00:00Added an answer on June 15, 2026 at 4:17 pm

    OK, using a BeanPostProcessor, register every bean of your interface:

    public class EventBusRegisterBeanPostProcessor implements BeanPostProcessor,
            ApplicationContextAware {
    
        private ApplicationContext context;
    
        @Autowired
        private EventBus eventBus; // The only event bus i assume...
    
        public Object postProcessBeforeInitialization(Object bean, String beanName)
                throws BeansException {
    
            return bean;
        }
    
        public Object postProcessAfterInitialization(Object bean, String beanName)
                throws BeansException {
    
            if (bean instanceof ILanguageChangeListener) {
                registerToEventBus(bean);
            }
    
            return bean;
        }
    
        private void registerToEventBus(Object bean) {
            this.eventBus.register(bean);
        }
    
        public void setApplicationContext(ApplicationContext applicationContext)
                throws BeansException {
            this.context = applicationContext;
        }
    
    }
    

    Note that if you have many EventBus beans, you should use the ApplicationContext.getBean(String) to get the EventBus you need.

    I quote from the javadoc:

    In case of a FactoryBean, this callback will be invoked for both the
    FactoryBean instance and the objects created by the FactoryBean (as of
    Spring 2.0). The post-processor can decide whether to apply to either
    the FactoryBean or created objects or both through corresponding bean
    instanceof FactoryBean checks.

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

Sidebar

Related Questions

Let's say, I have an application that access(read/write) the file system(files inside application), Active
Let's say I have the following entity: public class Store { public List<Product> Products
Let me frame it this way.. Say I have an application server running on
Let's say I have many items with click event (all have same element name
Let's say I have this interface: // .h @interface DataObject : NSObject { NSString*
Let's say that I have classes like this: public class Parent { public int
Let's say I have 2 windows in my application, and two classes responsible for
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in

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.