Will be great if you can give the files structure.
But base on the existing information, you can or programmatically set the Hibernate property, like:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
@Configuration
public class RedissonConfiguration {
@Value("${REDIS_MODE}")
private String redisMode;
@Autowired
private Environment env;
@Bean
public RedissonClient redissonClient() throws IOException {
String configFile = "redisson-" + redisMode + ".yaml";
Config config = Config.fromYAML(new File(configFile));
// Set hibernate properties programmatically
Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.cache.redisson.config", configFile);
applyHibernateProperties(hibernateProperties);
return Redisson.create(config);
}
private void applyHibernateProperties(Properties hibernateProperties) {
// Apply these properties to your Hibernate configuration
}
}
Or add property source annotation in your conf class:
@Configuration
@PropertySource("classpath:hibernate.properties")
public class HibernateConfig {
@Autowired
private Environment env;
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
// Now you can resolve ${REDIS_MODE}
String redisConfigFile = env.getProperty("hibernate.cache.redisson.config");
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
private Properties hibernateProperties() {
Properties properties = new Properties();
// This will now resolve the placeholder
properties.setProperty("hibernate.cache.redisson.config", env.getProperty("hibernate.cache.redisson.config"));
return properties;
}
}