解决多个环境下数据库配置。
3.1.1配置profile bean(在bean上配置@profile后,只有这个profile处于激活状态下,才会创建bean)
在javaconfig中配置
@Profile("dev"):在spring3.1中profile只能在累上使用,spring3.2之后就可以在方法上使用了(也就是一个类中可以配置多个了)
在xml中配置
<beans profile="dev" />
<beans profile="prod" />
3.1.2激活profile
spring.profiles.active与spring.profiles.default.
如果设置了active属性,那么active会激活。
如果没有设置active属性,将会查找defalut属性进行激活。
如果两个都没设置。不激活,不创建bean。
有多个方式设置两种属性:
作为DispatcherServlet的初始化参数
作为Web应用的上下文参数
作为JNDI条目
作为环境变量
作为jvm系统属性
在集成测试类上,使用@ActiveProfiles注解设置
3.1环境与profile
原文:https://www.cnblogs.com/-shing/p/e0b72dcd5b45753f9d5b11784c8a0b7e.html