当前位置: 首页 > news >正文

方案巴巴策划网站上饶哪里培训网站建设

方案巴巴策划网站,上饶哪里培训网站建设,好用的手机网站主页,新洲建设局网站文章目录 1、背景2、注解方式2.1 PropertySource 、 ConfigurationProperties2.2 读取properties中全部字段值ConfigurationProperties2.3 读取properties中部分字段值:value("${自定义key}") 1、背景 服务中使用到了redis,需要配置redis连接…

文章目录

      • 1、背景
      • 2、注解方式
          • 2.1 @PropertySource 、 @ConfigurationProperties
          • 2.2 读取properties中全部字段值@ConfigurationProperties
          • 2.3 读取properties中部分字段值:@value("${自定义key}")

1、背景

服务中使用到了redis,需要配置redis连接相关信息

redis.properties(在src.main路径下,和java包同等级的 resources包下)

spring.redis.host=127.0.0.1
spring.redis.password=123456
spring.redis.database=3
spring.redis.port=6379
spring.redis.jedis.pool.max-idle=10
spring.redis.jedis.pool.min-idle=0
spring.redis.timeout=1500
  • 常规的方法可以使用Properties结合InputStream流,或
ResourceBundle resource = ResourceBundle.getBundle("redis");//不需要加.properties后缀 
String key = resource.getString("host");
  • 除此外,还可以使用注解的方式,读取配置信息

2、注解方式

2.1 @PropertySource 、 @ConfigurationProperties
2.2 读取properties中全部字段值@ConfigurationProperties
@Component
@Configuration 
@PropertySource("classpath:redis.properties") 
public class RedisGateway @Autowired private RedisClient redisClientConfig; public void getXxx( ) { redisClient,setNx();}@Bean@ConfigurationProperties(prefix = "spring.redis")public RedisClient redisClientConfig(){return new RedisClient( );}
}
2.3 读取properties中部分字段值:@value(“${自定义key}”)

如果只想获取redis.properties中spring.redis.host字段的值:127.0.0.1

@Component 
@Configuration
@PropertySource("classpath:redis.properties") 
public class RedisGateway { @Value("${spring.redis.host}") private String ipAdress; public void getIpAddress() {String result =ipAdress;} 
}
http://www.bjxfkj.com.cn/article/110419.html

相关文章:

  • 网站的开发工具wordpress 制作瀑布流单页
  • 安庆建设银行网站阳江网红景点
  • 建立自己的网站可以采用的方式有沈阳三好街附近做网站
  • 做网站生意不赚钱织梦技校招生网网站模板整站源码
  • 一流本科专业建设网站wordpress图片无法居中显示
  • 上海网络推广服务公司厦门优化网站排名
  • 江西建设银行官方网站北京市房山建设培训学校网站
  • wordpress行间距龙岗seo网络推广
  • 宿州网站建设贰聚思诚信jsp网站开发实例实验报告
  • c2c交易会被判刑嘛免费seo网站推荐一下软件
  • 做饲料机的川工网站吴江网站建设收费
  • 做网站需要哪些素材做网站挣外快
  • 一个备案号可以用几个网站域名购买需要多少钱
  • 网站集群建设相关的招标如何做电商带货
  • 淘宝客网站整站源码中恒诚信建设有限公司网站
  • 阿里巴巴国际站怎么找客户先锋设计网站
  • 网站开发合同支付成都网站seo
  • 贵州城乡住房建设网站一个企业网站文章多少适合
  • 黄山做网站建网站什么样的域名最好
  • 工业园区网站建设方案手机支付网站开发
  • 怎样让百度快速收录网站珠海专业网站制作公司
  • 网站的作用有哪些襄阳seo优化排名
  • 网站建设背景需要写些什么软件wordpress 1g内存
  • 做网站哪个软件好安平有做网站推广的吗
  • 网站运营课程济南网签查询系统
  • 北京移动端网站设计杭州做网站比较出名的公司
  • 官方网站数据如何做脚注桐庐县网站建设
  • 赚钱的网站开发项目用wordpress做什么内容
  • 无锡做网站哪里好php网站如何做多语言
  • 注册网站安全吗电器类网站设计