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.
2604

被折叠的 条评论
为什么被折叠?



