zoukankan      html  css  js  c++  java
  • 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 }
    把每一件简单的事情做好,就是不简单;把每一件平凡的事情做好,就是不平凡!相信自己,创造奇迹~~
  • 相关阅读:
    tomcat配置服务器默认访问index页面
    AJAX跨域名
    MYSQL日期格式
    java群发邮箱
    判断execl格式
    java解析excel表格数据
    json解析数据
    generatorConfig自动生成
    简单后台调用api
    Spring邮箱发送
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/java_boot_bean.html
Copyright © 2011-2022 走看看