Hi Team,
I am using LocalsessionFactory where it takes apache BasicDataSource, I have requirement like password which we are setting while creating BasicDataSource needs to be pulled from a webservice. This localSessionFactory is all part of the @configuration , so it all gets loaded at application/server startup. Is there a way where we can reload the datasource/sessionfactory with new password, in case password is changed without restarting the applicaition or server.
@Bean public LocalSessionFactoryBean sessionFactory() throws SQLException \{ LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); sessionFactory.setPackagesToScan("com.arun.model"); sessionFactory.setAnnotatedPackages("com.arun.model"); sessionFactory.setHibernateProperties(hibernateProperties()); return sessionFactory; }
public DataSource dataSource() throws SQLException \{
{noformat} decryptedQtzPassword = getFromWebservice(); if (quartzDataSource == null) { quartzDataSource = new BasicDataSource(); quartzDataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); quartzDataSource.setUsername(decryptedQtzUserID); quartzDataSource.setPassword(decryptedQtzPassword); quartzDataSource.setUrl(decryptedUrl); } logger.info("Database Qtz pwd :: "+decryptedQtzPassword); return quartzDataSource; }{noformat}
@Autowired private SessionFactory sessionFactory;
{noformat}public Session getSession() throws HibernateException { return sessionFactory.getCurrentSession(); }{noformat}
|
|