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

制度建设对网站管理的重要性网站建设设计说明书

制度建设对网站管理的重要性,网站建设设计说明书,服装网站的建设策划,太原网站关键词排名1. 区分环境的配置 1.1. properties 配置 假设,一个应用的工作环境有:dev、test、prod 那么,我们可以添加 4 个配置文件: applcation.properties - 公共配置application-dev.properties - 开发环境配置application-test.proper…
1. 区分环境的配置
1.1. properties 配置

假设,一个应用的工作环境有:dev、test、prod
那么,我们可以添加 4 个配置文件:

  • applcation.properties - 公共配置
  • application-dev.properties - 开发环境配置
  • application-test.properties - 测试环境配置
  • application-prod.properties - 生产环境配置

在 applcation.properties 文件中可以通过以下配置来激活 profile:
spring.profiles.active = test
在这里插入图片描述

1.2. yml 配置

与 properties 文件类似,我们也可以添加 4 个配置文件:

  • applcation.yml - 公共配置
  • application-dev.yml - 开发环境配置
  • application-test.yml - 测试环境配置
  • application-prod.yml - 生产环境配置

在 applcation.yml 文件中可以通过以下配置来激活 profile:

spring:profiles:active: prod

此外,yml 文件也可以在一个文件中完成所有 profile 的配置:

# 激活 prod
spring:profiles:active: prod
# 也可以同时激活多个 profile
# spring.profiles.active: prod,proddb,prodlog
---
# dev 配置
spring:profiles: dev# 略去配置---
spring:profiles: test# 略去配置---
spring.profiles: prod
spring.profiles.include:- proddb- prodlog---
spring:profiles: proddb# 略去配置---
spring:profiles: prodlog
# 略去配置

注意:不同 profile 之间通过 — 分割

2. 区分环境的代码

使用 @Profile 注解可以指定类或方法在特定的 Profile 环境生效。

2.1. 修饰类
@Configuration
@Profile("production")
public class JndiDataConfig {@Bean(destroyMethod="")public DataSource dataSource() throws Exception {Context ctx = new InitialContext();return (DataSource) ctx.lookup("java:comp/env/jdbc/datasource");}
}
2.2. 修饰注解
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Profile("production")
public @interface Production {
}
2.3. 修饰方法
@Configuration
public class AppConfig {@Bean("dataSource")@Profile("development")public DataSource standaloneDataSource() {return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).addScript("classpath:com/bank/config/sql/schema.sql").addScript("classpath:com/bank/config/sql/test-data.sql").build();}@Bean("dataSource")@Profile("production")public DataSource jndiDataSource() throws Exception {Context ctx = new InitialContext();return (DataSource) ctx.lookup("java:comp/env/jdbc/datasource");}
}
3. 激活 profile
3.1. 插件激活 profile

spring-boot:run -Drun.profiles=prod

3.2. main 方法激活 profile

–spring.profiles.active=prod

3.3. jar 激活 profile

java -jar -Dspring.profiles.active=prod *.jar

3.4. 在 Java 代码中激活 profile

直接指定环境变量来激活 profile:

System.setProperty("spring.profiles.active", "test");

在 Spring 容器中激活 profile:

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.getEnvironment().setActiveProfiles("development");
ctx.register(SomeConfig.class, StandaloneDataConfig.class, JndiDataConfig.class);
ctx.refresh();
http://www.yayakq.cn/news/675951/

相关文章:

  • 免费自媒体网站广州站西手表
  • 网站海外推广服务免费自助建站怎么样
  • win7系统做网站服务器石龙建设网站
  • 大城县建设局网站wordpress建站行吗
  • 做ppt高手 一定要常去这八个网站公众号的网站开发
  • 茂名手机网站制作免费做外贸的网站建设
  • 网站左侧的导航是怎么做的网站仿站
  • 做伤残鉴约号网站网站建设谈单技巧
  • 重庆建设安全管理网站平面设计工作好找吗
  • 购物网站制作例子网络设计开题报告
  • 海口有哪几家是做网站的电脑网站做淘宝客
  • 都什么企业需要网站吗版面设计的概念是什么
  • html源码网站下载之家网上企业推广
  • 建设银行河北分行招聘网站石家庄官网
  • 利用wix建手机网站音乐网站如何做
  • 王烨飞变形计厦门seo关键词排名
  • 常见c2c网站有哪些做微信首图的网站
  • 国外网站如何做推广网站地图怎么做、
  • GTA5浏览器网站建设中网站域名如何使用方法
  • 制作企业网站的流程网络营销服务
  • 个人博客网站怎么赚钱衡水网站建设公司哪家比较好
  • 北京企业网站怎么建设国家企业信用信息查询公示系统
  • 个人印章在线制作网站如何做流量网站
  • 深圳做自适应网站公司广州经济技术开发区
  • 好看网站江门seo
  • 网站建设的参考书籍百度搜索推广
  • 长春 美容 网站建设一个好的网站怎么建设
  • 深圳 企业 网站建设wordpress点文章标题怎么出现错误
  • 无锡网站制作优化排名seo描述是什么意思
  • 安徽建设厅网站施wordpress 完美搬家