How to reload configuration of Spring bean when particular database record is updated?

654 views Asked by At

I am loading keystore in Spring WS via JPA from database.

@Bean(name = "keyStore")
@Primary
KeyStoreFactoryBean keyStore() throws Exception {

    try {
        KeyStore keyStore = keyService.keyStore();

        KeyStoreFactoryBean keyStoreFactory = new KeyStoreFactoryBean();
        keyStoreFactory.setPassword(keyStore.getPassword());
        keyStoreFactory.setLocation(keyStore.asResource());
        keyStoreFactory.afterPropertiesSet();

        return keyStoreFactory;

    } catch (Exception e) {
        throw e;
    }

}

This code works, but if I update keystore record in database, KeyStoreFactoryBean is not reloaded (obviously). I aware of scope anotation for beans but not sure what scope is best for this situation?

How to "reload" this bean everytime database record is changed?

0

There are 0 answers