【Spring】 (5)根据机器环境不同运行不同代码
来源:互联网 发布:软件著作权变更费用 编辑:程序博客网 时间:2024/05/17 05:06
package com.example.demo_2_4;/** * Created by WangBin on 2017/4/13. * */public class DemoBean { private String content; public DemoBean(String content) { this.content = content; } public String getContent() { return content; } public void setContent(String content) { this.content = content; }}
package com.example.demo_2_4;import org.springframework.context.annotation.AnnotationConfigApplicationContext;/** * Created by WangBin on 2017/4/13. * */public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); System.err.println(""+context.getEnvironment()); context.getEnvironment().setActiveProfiles("dev");//先将活动的Profile设置1下 context.register(ProfileConfig.class);//设置 config context.refresh();//刷新容器 DemoBean demoBean = context.getBean(DemoBean.class); System.err.println(demoBean.getContent()); context.close(); }}
package com.example.demo_2_4;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Profile;/** * Created by WangBin on 2017/4/13. * */@Configurationpublic class ProfileConfig { @Bean @Profile("dev")//Profile 为 dev时 实例化 devDemoBean public DemoBean devDemoBean(){ return new DemoBean("dev实例化的"); } @Bean @Profile("prod")//Profile 为 prod时 实例化 proDemoBean public DemoBean proDemoBean(){ return new DemoBean("pro实例化的"); }}
package com.example.demo_2_4;import org.springframework.web.WebApplicationInitializer;import javax.servlet.ServletContext;import javax.servlet.ServletException;/** * Created by WangBin on 2017/4/13. * */public class WebInit implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("spring.profiles.default","dev"); }}
阅读全文
0 0
- 【Spring】 (5)根据机器环境不同运行不同代码
- maven根据不同的运行环境,打包不同的配置文件
- Spring MVC 根据不同环境加载不同的配置文件
- spring boot profiles根据不同环境指定不同配制
- 根据不同环境加载不同js文件
- 根据不同环境加载不同js文件
- Maven根据不同环境打包不同配置文件
- Maven根据不同环境打包不同配置文件
- 根据不同环境读取不同配置文件
- Maven根据不同环境打包不同配置文件
- Maven根据不同环境打包不同配置文件
- Maven根据不同环境打包不同配置文件
- Maven根据不同环境打包不同配置文件
- maven根据不同环境打包
- 同一个程序不同环境运行结果不同?
- maven 不同环境加载不同spring配置文件
- java不同环境运行模式
- Maven根据不同个环境打包, 获取不同的配置文件
- vue.js-脚手架
- 记录IDEA学习过程——第一集
- H-Index
- BZOJ 2763 [JLOI2011]飞行路线
- gitlab-runner-maven卡死的情况
- 【Spring】 (5)根据机器环境不同运行不同代码
- 文件上传漏洞(绕过姿势) 转载防丢失
- 简单运算工厂
- 使用CSS伪元素模拟float:center效果
- 跨域
- Hyperledger Fabric SDK 示例fabric-samples-《balance-transfer》之四《安装chaincode》
- 可能是Android最简单的欢迎页面实现
- zabbix通过snmp监控带外管理ping不可用的问题
- 3、认识目标客户:6个角度与2步阶梯