Spring Profile基本使用
来源:互联网 发布:灰色关联分析法 编程 编辑:程序博客网 时间:2024/04/29 21:28
Spring profile是Spring 3引入的概念,一般系统开发的时候更喜欢使用Maven中的profile来进行不同环境配置文件的区分。Spring的profile一直没有怎么使用,最近在一个公司系统开发过程中同事使用了Spring profile。可是在设置default profile上遇到了麻烦。跟着一起研究了半天,才发现了问题所在。
Spring profile在我们系统中的使用非常简单,并没有使用runtime的特性,只是在xml中定义了不同profile环境中的beans
<!-- other beans --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> ....... <!-- production环境 --> <beans profile="production"> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.properties" /> .... </beans> <!-- local环境 --> <beans profile="local"> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.properties ,classpath*:/application.development.properties"/> .... </beans>
接下来我们一般可以通过在web.xml,在properties中来选择使用什么环境的profile,例如
<!-- web.xml --> <context-param> <param-name>spring.profiles.default</param-name> <param-value>production</param-value> </context-param> <!-- properties选择 --> System.setProperty("spring.profiles.active", "development");
我们的问题出在哪里呢?出在了我们想通过jndi而不是jvm参数来选择默认的profile,首先我们知道spring profile的设置不能在properties文件里,因为spring的加载顺序。我们不想改变系统的启动参数,所以选择了jndi的方式来读取profile的默认启动,关键来了,在配置jndi的时候我们进行了以下设置
<Environment name="spring.profiles.active" type="java.lang.String" value="local">
悲哀的发现不起作用,spring的log里面也没有任何有用的提示,还没到获取profile相关的log就因为读取不到bean挂了。只好去掉了profile相关的xml文件重启启动一次系统才发现spring默认读取的jndi名字是spring.profiles.default而不是spring.profiles.active。
1 0
- Spring Profile基本使用
- spring profile的基本使用
- Spring Profile 使用
- spring profile使用事项
- Spring Boot Profile使用
- Spring @Profile标签使用:
- spring @profile注解的使用
- spring使用profile选择配置文件
- spring @profile注解的使用
- Maven与Spring profile的结合使用
- spring boot 使用profile来分区配置
- Spring框架总结之Profile使用
- spring-boot使用profile环境切换
- spring boot 使用profile来分区配置
- Spring Boot 03 profile的使用
- spring boot 使用profile来分区配置
- Spring profile
- spring profile
- linux时间片轮转小程序
- (java)Increasing Triplet Subsequence
- 卷积神经网络(CNN)的简单实现(MNIST)
- C++ —— 运算符重载
- ehcart 多图 饼图和柱状图 echart多图加载问题
- Spring Profile基本使用
- 按键消抖&&testbench
- SSH(二)----Hibernate工作原理
- 二叉树的递归与非递归遍历实现
- Core Java (七) Java中的static修饰符
- Jquery Mobile 入门1 (介绍&组件1)
- 框架学习
- Search in Rotated Sorted Array
- HIve的JavaAPI操作