1. 程式人生 > 其它 >springboot注入一個jar包裡的bean

springboot注入一個jar包裡的bean

 1 import com.yonyou.iuap.context.ContextHolder;
 2 import com.yonyou.yht.cache.CacheManager;
 3 import com.yonyou.yht.cache.redis.RedisPoolFactory;
 4 import org.springframework.beans.factory.annotation.Value;
 5 import org.springframework.context.annotation.Bean;
 6 import org.springframework.context.annotation.Configuration;
7 import org.springframework.context.annotation.Scope; 8 import org.springside.modules.nosql.redis.JedisTemplate; 9 import org.springside.modules.nosql.redis.pool.JedisPool; 10 11 /** 12 * @author jiashubing 13 * @since 2019/12/23 14 */ 15 @Configuration 16 public class BeanConfig { 17 18 @Value("${redis.url}")
19 private String redisUrl; 20 21 @Value("${sessionTimeout}") 22 private int sessionTimeout; 23 24 @Bean("redisPool") 25 @Scope("prototype") 26 public JedisPool redisPoolFactory() { 27 return RedisPoolFactory.createJedisPool(redisUrl); 28 } 29 30 @Bean("jedisTemplate")
31 public JedisTemplate jedisTemplate() { 32 JedisPool redisPool = ContextHolder.getContext().getBean(JedisPool.class); 33 return new SwitchableJedisTemplate(redisPool); 34 } 35 36 @Bean("cacheManager") 37 public CacheManager cacheManager() { 38 JedisTemplate jedisTemplate = ContextHolder.getContext().getBean(JedisTemplate.class); 39 CacheManager cacheManager = new CacheManager(); 40 cacheManager.setJedisTemplate(jedisTemplate); 41 cacheManager.setSessionTimeout(sessionTimeout); 42 int reConnectionTime = 50; 43 cacheManager.setReConnectionTime(reConnectionTime); 44 return cacheManager; 45 } 46 }
把每一件簡單的事情做好,就是不簡單;把每一件平凡的事情做好,就是不平凡!相信自己,創造奇蹟~~