Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. spring.profile = ${mySpringProfile}
  2.  
  3. <context-param>
  4. <param-name>spring.profiles.active</param-name>
  5. <param-value>${mySpringProfile}</param-value>
  6. </context-param>
  7.  
  8. <profiles>
  9. <profile>
  10. <id>postgres</id>
  11. <activation>
  12. <activeByDefault>true</activeByDefault>
  13. <property>
  14. <name>spring.profiles.active</name>
  15. <value>postgres</value>
  16. </property>
  17. </activation>
  18. <dependencies>
  19. <dependency>
  20. <groupId>postgresql</groupId>
  21. <artifactId>postgresql</artifactId>
  22. <version>9.1-901.jdbc4</version>
  23. </dependency>
  24. </dependencies>
  25. </profile>
  26. <profile>
  27. <id>h2</id>
  28. <activation>
  29. <property>
  30. <name>spring.profiles.active</name>
  31. <value>h2</value>
  32. </property>
  33. </activation>
  34. <dependencies>
  35. <dependency>
  36. <groupId>com.h2database</groupId>
  37. <artifactId>h2</artifactId>
  38. <version>1.4.191</version>
  39. </dependency>
  40. </dependencies>
  41. </profile>
  42. </profiles>
  43.  
  44. <context-param>
  45. <param-name>spring.profiles.default</param-name>
  46. <param-value>postgres</param-value>
  47. </context-param>
  48.  
  49. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  50. <property name="dataSource" ref="mainDataSource" />
  51. <property name="jpaVendorAdapter">
  52. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
  53. </property>
  54. <property name="jpaProperties" ref="hibProps"/>
  55. <property name="packagesToScan">
  56. <list>
  57. <value>my.test.model</value>
  58. </list>
  59. </property>
  60. </bean>
  61. ...
  62. <beans profile="postgres">
  63. <bean name="mainDataSource"
  64. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  65. <property name="driverClassName" value="org.postgresql.Driver" />
  66. <property name="url" value="jdbc:postgresql://127.0.0.1:5432/webchat" />
  67. <property name="username" value="postgres" />
  68. <property name="password" value="postgres" />
  69. </bean>
  70. </beans>
  71.  
  72. <beans profile="h2">
  73. <bean name="mainDataSource"
  74. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  75. <property name="driverClassName" value="org.h2.Driver" />
  76. <property name="url" value="jdbc:h2:file:./newsdb;INIT=RUNSCRIPT FROM 'classpath:init.sql';TRACE_LEVEL_FILE=0" />
  77. <property name="username" value="sa" />
  78. <property name="password" value="" />
  79. </bean>
  80. </beans>
  81.  
  82. <modelVersion>4.0.0</modelVersion>
  83.  
  84. ...
  85.  
  86. <profiles>
  87. <profile>
  88. <id>dev</id>
  89. <activation>
  90. <!-- Default to dev so we avoid any accidents with prod! :) -->
  91. <activeByDefault>true</activeByDefault>
  92. </activation>
  93. <properties>
  94. <!-- This can be a single value, or a comma-separated list -->
  95. <spring.profiles.to.activate>dev</spring.profiles.to.activate>
  96. </properties>
  97. </profile>
  98. <profile>
  99. <id>uat</id>
  100. <properties>
  101. <!-- This can be a single value, or a comma-separated list -->
  102. <spring.profiles.to.activate>uat</spring.profiles.to.activate>
  103. </properties>
  104. </profile>
  105. <profile>
  106. <id>prod</id>
  107. <properties>
  108. <!-- This can be a single value, or a comma-separated list -->
  109. <spring.profiles.to.activate>prod</spring.profiles.to.activate>
  110. </properties>
  111. </profile>
  112. </profiles>
  113.  
  114. ...
  115.  
  116. <build>
  117. <plugins>
  118. <plugin>
  119. <groupId>org.apache.maven.plugins</groupId>
  120. <artifactId>maven-war-plugin</artifactId>
  121. <version>2.6</version>
  122. <configuration>
  123. <webResources>
  124. <webResource>
  125. <filtering>true</filtering>
  126. <directory>src/main/webapp</directory>
  127. <includes>
  128. <include>**/web.xml</include>
  129. </includes>
  130. </webResource>
  131. </webResources>
  132. <failOnMissingWebXml>true</failOnMissingWebXml>
  133. </configuration>
  134. </plugin>
  135. ...
  136. </plugins>
  137. </build>
  138.  
  139. <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  140. Setup for root Spring context
  141. -->
  142. <listener>
  143. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  144. </listener>
  145. <context-param>
  146. <param-name>contextConfigLocation</param-name>
  147. <param-value>/WEB-INF/spring-core-config.xml</param-value>
  148. </context-param>
  149. <!--
  150. Jim Tough - 2016-11-30
  151. Per Spring Framework guide: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-environment
  152.  
  153. ...profiles may also be activated declaratively through the spring.profiles.active
  154. property which may be specified through system environment variables, JVM system
  155. properties, servlet context parameters in web.xml, or even as an entry in JNDI.
  156. -->
  157. <context-param>
  158. <param-name>spring.profiles.active</param-name>
  159. <param-value>${spring.profiles.to.activate}</param-value>
  160. </context-param>
  161. <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
  162.  
  163. @Configuration
  164. @Profile({"dev","default"})
  165. @ComponentScan
  166. @EnableTransactionManagement
  167. @EnableSpringDataWebSupport
  168. public class PersistenceContext {
  169. // ...
  170. }
  171.  
  172. <profile>
  173. <id>dev</id>
  174. <properties>
  175. <activatedProperties>dev</activatedProperties>
  176. </properties>
  177. <activation>
  178. <activeByDefault>true</activeByDefault>
  179. </activation>
  180. </profile>
  181. <profile>
  182. <id>release</id>
  183. <properties>
  184. <activatedProperties>release</activatedProperties>
  185. </properties>
  186. </profile>
  187.  
  188. <build>
  189. <resources>
  190. <resource>
  191. <directory>src/main/resources</directory>
  192. <filtering>true</filtering>
  193. </resource>
  194. </resources>
  195. </build>
  196.  
  197. spring.profiles.active=@activatedProperties@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement