码迷,mamicode.com
首页 > 编程语言 > 详细

springboot 的常用操作

时间:2017-10-25 19:45:27      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:int   ati   get   结构   .com   span   component   bsp   特定   

1. 使用@Value注解,可以直接将属性值注入到你的beans中,并通过Spring 的Environment抽象或绑定到结构化对象来访问。

import org.springframework.stereotype.*
import org.springframework.beans.factory.annotation.*
@Component
public class MyBean {
@Value("${name}")
private String name;
// ...
}

2. 配置随机值

my.secret=${random.value}
my.number=${random.int}
my.bignumber=${random.long}
my.number.less.than.ten=${random.int(10)}
my.number.in.range=${random.int[1024,65536]}

3. @ConfigurationProperties 

@ConfigurationProperties(prefix="my")
public class Config {
private List<String> servers = new ArrayList<String>();
public List<String> getServers() {
return this.servers;
}
}

my.servers[0]=dev.bar.com
my.servers[1]=foo.bar.com

4.Profiles

   Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只能在特定的环境下生效。任何@Component或 @Configuration都能被@Profile标记,从而限制加载它的时机。

@Configuration
@Profile("production")
public class ProductionConfiguration {
// ...
}

springboot 的常用操作

标签:int   ati   get   结构   .com   span   component   bsp   特定   

原文地址:http://www.cnblogs.com/jishan-coder/p/7731548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!