2 more huge 1.5 --> 2.x upgrade stoppers: Configuration interfaces and AppBeans

We make very, very heavy use of both Configuration interfaces and the old AppBeans method for getting services and such all over the place.

Both of these have been removed - what is the best advice as to how to replace this functionality as it is completely vital to our app?

(And in the case of Configuration interfaces; how would one convert the already-in-the-database values for the configs?)

Hello Jon

Here is anAppBeans implementation that I am using, which was recommend to me in an earlier post.

import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

public class AppBeans {
    private static ApplicationContext applicationContext;

    private static void setApplicationContext(ApplicationContext applicationContext) {
        AppBeans.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static <T> T getBean(Class<T> beanClass) {
        return applicationContext.getBean(beanClass);
    }

    @Component
    static class ApplicationContextRetriever {

        @EventListener
        public void storeApplicationContext(ContextRefreshedEvent event) {
            AppBeans.setApplicationContext(event.getApplicationContext());
        }
    }
}

I hope this helps.

Best regards
Chris

1 Like

Hello @modemmisuser,

Yes, you can use the approach recommended above. Or you can use applicationContext directly.

As for properties, you can transfer them from the database to application.properties or use the ApplicationSetting add-on.

Application Settings:
https://docs.jmix.io/jmix/appsettings/index.html

Regards,
Nikita

Yeah, I have a similar implementation that I got from Konstantin, I just wasn’t sure if it worked in 2.x since so much was changed. (They really should have just renamed the project yet again, IMO.)

There are literally hundreds upon hundreds of these; you guys encouraged heavy usage of configuration interfaces and we absolutely went with it.

Some method of migrating them to something that works in 2.x is required. They cannot be in app.properties as users need to configure them at will.