本篇文章给大家谈谈java–SpringProfile包含yaml文件的问题,以及springyaml配置的知识点,同时本文还将给你拓展INI文件编程,WINAPI函数WritePrivateProf
本篇文章给大家谈谈java – Spring Profile包含yaml文件的问题,以及spring yaml配置的知识点,同时本文还将给你拓展INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString、Java 类中 @Profile 注解 springboot 切换不同环境配置、Java之Spring认证使用Profile配置运行环境讲解、Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- java – Spring Profile包含yaml文件的问题(spring yaml配置)
- INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
- Java 类中 @Profile 注解 springboot 切换不同环境配置
- Java之Spring认证使用Profile配置运行环境讲解
- Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程
java – Spring Profile包含yaml文件的问题(spring yaml配置)
当团队设置websphere配置文件激活时,我正在尝试完成云配置文件也已激活.
yaml文件
---
spring:
application:
name: kicapp
output:
ansi:
enabled: ALWAYS
profiles:
active: local
#server:
#context-path: /
#port: 8080
#logging:
#level:
#org.springframework.security: DEBUG
---
spring:
profiles: local
---
spring:
profiles: unittest
---
spring:
profiles: cloud
test: loaded
---
spring:
profiles: websphere
include: cloud
当我设置–spring.profiles.active = websphere时,我收到以下错误
Caused by: mapping values are not allowed here in ‘reader’,line 28,
column 12:
include: cloud
一个好的解决方法实际上是通过这种方式将其拆分为多个文件:
具有共同内容的application.yaml,
应用程序 – <型材>使用特定于配置文件的扩展,使用此结构键spring.profiles.include将按预期工作.
INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString
总结
以上是小编为你收集整理的INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Java 类中 @Profile 注解 springboot 切换不同环境配置
下面 2 个不同的类实现了同一个接口,@Profile 注解指定了具体环境
// 接口定义
public interface SendMessage {
// 发送短信方法定义
public void send();
}
// Dev 环境实现类
@Component
@Profile("dev")
public class DevSendMessage implements SendMessage {
@Override
public void send() {
System.out.println(">>>>>>>>Dev Send()<<<<<<<<");
}
}
// Stg环境实现类
@Component
@Profile("stg")
public class StgSendMessage implements SendMessage {
@Override
public void send() {
System.out.println(">>>>>>>>Stg Send()<<<<<<<<");
}
}
// 启动类
@SpringBootApplication
public class ProfiledemoApplication {
@Value("${app.name}")
private String name;
@Autowired
private SendMessage sendMessage;
@PostConstruct
public void init(){
sendMessage.send();// 会根据profile指定的环境实例化对应的类
}
}
在启动程序的时候通过添加 –spring.profiles.active={profile} 来指定具体使用的配置
例如我们执行 java -jar demo.jar –spring.profiles.active=dev 那么下面三个文件中的内容将被如何应用?
Spring Boot 会先加载默认的配置文件,然后使用具体指定的 profile 中的配置去覆盖默认配置。
application.properties
app.name=MyApp
server.port=8080
spring.profiles.active=dev
application-dev.properties
server.port=8081
application-stg.properties
server.port=8082
Java之Spring认证使用Profile配置运行环境讲解
这篇文章主要介绍了Java之Spring认证使用Profile配置运行环境讲解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
Spring提供了@Profile注解来解决程序在不同运行环境时候的配置差别。
项目开发时候大多包含:开发、测试、上线运行几个过程,在每个过程中软件的工作环境一般多少有些差别,比如:在开发阶段利用本地数据库、测试阶段采用测试数据库、在上线运行阶段使用生产数据库。这些差别如果采用了手工维护就会存在各种问题:效率低下、容易发生人为因素意外错误。
利用Spring提供的@Profile注解就可以定义程序不同的运行场景配置,配置以后在启动程序时候给定不同的启动参数就可以灵活的切换运行场景,不再需要人工干预,这样就可以大大提升开发效率。
以配置开发环和生产境数据源为例子,具体说明使用步骤:
在Spring配置文件中利用@Profile声明开发环境和生产环境使用的数据源:
@Configuration public class DataSourceConfig { @Bean(name="dataSource") //重写BeanID @Profile("dev") //配置开发环境使用的数据源 public DataSource dataSourceForDev() { DruidDataSource dataSource = new DruidDataSource(); ... return dataSource; } @Bean(name="dataSource")//重写BeanID @Profile("production")//配置生产环境使用的数据源 public DataSource dataSourceForProd() { DruidDataSource dataSource = new DruidDataSource(); ... return dataSource; } }
其中“dev”表示开发环境,“production”表示生产环境,显然有两个BeanID是“dataSource”的数据源Bean对象,这两个对象不会同时初始化,Spring会根据激活的Profile属性初始化其中一个数据源Bean对象。
使用如下启动命令参数-Dspring.profiles.active=dev就可以设置当前激活的Profile是发环境“dev”,此时Spring会初始化属于开发环境的数据源Bean对象:
java -Dspring.profiles.active=dev -jar demo.jar
或者在SpringBoot的启动类中使用系统属性设置激活的Profile:
System.setProperty("spring.profiles.active" , "dev"); SpringApplication.run(AppConfig.class);
在测试时候可以使用 @ActiveProfiles注解设置当前激活的Profile。
到此这篇关于Java之Spring认证使用Profile配置运行环境讲解的文章就介绍到这了,更多相关Java之Spring认证使用Profile配置内容请搜索小编以前的文章或继续浏览下面的相关文章希望大家以后多多支持小编!
Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程
在登录Linux时要执行文件的过程如下:
在刚登录Linux时,首先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile、 ~/.bash_login或 ~/.profile文件中的其中一个,
执行的顺序为:~/.bash_profile、 ~/.bash_login、 ~/.profile。
如果 ~/.bash_profile文件存在的话,一般还会执行 ~/.bashrc文件。
因为在 ~/.bash_profile文件中一般会有下面的代码:
if [ -f ~/.bashrc ] ; then
. ./bashrc
fi
~/.bashrc中,一般还会有以下代码:
if [ -f /etc/bashrc ] ; then
. /etc/bashrc
fi
所以,~/.bashrc会调用 /etc/bashrc文件。最后,在退出shell时,还会执行 ~/.bash_logout文件。
执行顺序为: /etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout
关于各个文件的作用域,在网上找到了以下说明:
(1) /etc/profile: 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。
(2) /etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取(即每次新开一个终端,都会执行bashrc)。
(3) ~/.bash_profile: 每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次。默认情况下,设置一些环境变量,执行用户的.bashrc文件。
(4) ~/.bashrc: 该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。
(5) ~/.bash_logout: 当每次退出系统(退出bash shell)时,执行该文件. 另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承 /etc/profile中的变量,他们是"父子"关系。
(6) ~/.bash_profile: 是交互式、login 方式进入 bash 运行的~/.bashrc 是交互式 non-login 方式进入 bash 运行的通常二者设置大致相同,所以通常前者会调用后者。
/etc/profile和/etc/environment等各种环境变量设置文件的用处
1)先将export LANG=zh_CN加入/etc/profile,退出系统重新登录,登录提示显示英文。
2)先将/etc/profile 中的export LANG=zh_CN删除,将LNAG=zh_CN加入/etc/environment,退出系统重新登录,登录提示显示中文。
用户环境建立的过程中总是先执行/etc/profile,然后再读取/etc/environment。为什么会有如上所叙的不同呢?而不是先执行/etc/environment,后执行/etc/profile呢?
这是因为: /etc/environment是设置整个系统的环境,而/etc/profile是设置所有用户的环境,前者与登录用户无关,后者与登录用户有关。
系统应用程序的执行与用户环境可以是无关的,但与系统环境是相关的,所以当你登录时,你看到的提示信息,如日期、时间信息的显示格式与系统环境的LANG是相关的,缺省LANG=en_US,如果系统环境LANG=zh_CN,则提示信息是中文的,否则是英文的。
对于用户的shell初始化而言是先执行/etc/profile,再读取文件/etc/environment;对整个系统而言是先执行/etc/environment。这样理解正确吗?
登陆系统时的顺序应该是
/etc/enviroment --> /etc/profile --> $HOME/.profile -->$HOME/.env (如果存在)
/etc/profile 是所有用户的环境变量
/etc/enviroment是系统的环境变量
登陆系统时shell读取的顺序应该是
/etc/profile ->/etc/enviroment -->$HOME/.profile -->$HOME/.env
原因应该是用户环境和系统环境的区别了,如果同一个变量在用户环境(/etc/profile)和系统环境(/etc/environment)有不同的值,那应该是以用户环境为准了。
今天关于java – Spring Profile包含yaml文件的问题和spring yaml配置的讲解已经结束,谢谢您的阅读,如果想了解更多关于INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString、Java 类中 @Profile 注解 springboot 切换不同环境配置、Java之Spring认证使用Profile配置运行环境讲解、Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程的相关知识,请在本站搜索。
本文标签: