多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 基于JAVA配置方式 * Bean对象默认为方法名 ``` @Configuration @EnableAutoConfiguration public class RedisConfig { @Bean @ConfigurationProperties(prefix = "spring.redis.pool") public JedisPoolConfig getRedisConfig() { JedisPoolConfig config = new JedisPoolConfig(); return config; } @Bean @ConfigurationProperties(prefix = "spring.redis") public JedisConnectionFactory getConnectionFactory() { JedisConnectionFactory factory = new JedisConnectionFactory(); factory.setUsePool(true); JedisPoolConfig config = getRedisConfig(); factory.setPoolConfig(config); logger.info("JedisConnectionFactory bean init success."); return factory; } @Bean public RedisTemplate<?, ?> getRedisTemplate() { JedisConnectionFactory factory = getConnectionFactory(); logger.info(this.host+","+factory.getHostName()+","+factory.getDatabase()); logger.info(this.password+","+factory.getPassword()); logger.info(factory.getPoolConfig().getMaxIdle()); RedisTemplate<?, ?> template = new StringRedisTemplate(getConnectionFactory()); return template; } } ``` ### 在JavaConfig中引用XML:@ImportResource![](../assets/201803290003001.png)