@profile 的使用

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。

目录

概 述

profile
结合写的配置类,用来设置的Spring 设置当前环境和,动态激活一列列的组件的功能。
开发环境,测试环境,生产环境,A组件,B组件,测试人员用,具备动态激活,完成这个功能。
首先设置几个数据源,数据源,

@value 取出配置文件中的数值,密码用in工艺中。
String valueResolver;
的数值,3个数据源testDataSource,
applicationCOntext.名字打印出来,test

2.2 激活方式
激活方式一

spring.profiles.active 激活方式
如果 spring.profiles.active 未配置, 使用spring.profiles.default激活方式
如果前面都为配置,就会加载没有定义在profile中的bean;

激活方式:

spring.profiles.active
dev


zszxzServlet
org.springframework.web.servlet.DispatcherServlet

spring.profiles.default
dev

1


zszxzServlet
/

激活方式三:
@RunWith(SpringJUnit4ClassRunner.class)//创建spring应用上下文
@ContextConfiguration(classes= DataSourceConfig.class)//加载配置类
@ActiveProfiles(“dev”)
public class ProfileTest {

@Autowired
private DataSource dataSource;

@Test
public void sheetTest(){
    JdbcTemplate jdbc = new JdbcTemplate(dataSource);
    List<String> query = jdbc.query("select * from customer", new RowMapper<String>() {
        @Override
        public String mapRow(ResultSet rs, int rowNum) throws SQLException {
            return rs.getLong("id") + ":" + rs.getString("customer_name");
        }
    });
    
    System.out.println(query);
}

}

小结

参考资料和推荐阅读

1.链接: link.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

迅捷的软件产品制作专家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值