如何在更新特定数据库记录时重新加载Spring bean的配置?

时间:2016-12-23 16:51:34

标签: java spring spring-bean

我通过数据库中的keystore在Spring WS中加载JPA

@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;
    }

}

此代码有效,但如果我更新数据库中的密钥库记录,则KeyStoreFactoryBean不会重新加载(显然)。我知道bean的scope anotation但不确定scope最适合这种情况的是什么?

如何"重新加载"每次更改数据库记录时该bean是什么?

0 个答案:

没有答案