Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- spring.profile = ${mySpringProfile}
- <context-param>
- <param-name>spring.profiles.active</param-name>
- <param-value>${mySpringProfile}</param-value>
- </context-param>
- <profiles>
- <profile>
- <id>postgres</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- <property>
- <name>spring.profiles.active</name>
- <value>postgres</value>
- </property>
- </activation>
- <dependencies>
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>9.1-901.jdbc4</version>
- </dependency>
- </dependencies>
- </profile>
- <profile>
- <id>h2</id>
- <activation>
- <property>
- <name>spring.profiles.active</name>
- <value>h2</value>
- </property>
- </activation>
- <dependencies>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.4.191</version>
- </dependency>
- </dependencies>
- </profile>
- </profiles>
- <context-param>
- <param-name>spring.profiles.default</param-name>
- <param-value>postgres</param-value>
- </context-param>
- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="mainDataSource" />
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
- </property>
- <property name="jpaProperties" ref="hibProps"/>
- <property name="packagesToScan">
- <list>
- <value>my.test.model</value>
- </list>
- </property>
- </bean>
- ...
- <beans profile="postgres">
- <bean name="mainDataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="org.postgresql.Driver" />
- <property name="url" value="jdbc:postgresql://127.0.0.1:5432/webchat" />
- <property name="username" value="postgres" />
- <property name="password" value="postgres" />
- </bean>
- </beans>
- <beans profile="h2">
- <bean name="mainDataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="org.h2.Driver" />
- <property name="url" value="jdbc:h2:file:./newsdb;INIT=RUNSCRIPT FROM 'classpath:init.sql';TRACE_LEVEL_FILE=0" />
- <property name="username" value="sa" />
- <property name="password" value="" />
- </bean>
- </beans>
- <modelVersion>4.0.0</modelVersion>
- ...
- <profiles>
- <profile>
- <id>dev</id>
- <activation>
- <!-- Default to dev so we avoid any accidents with prod! :) -->
- <activeByDefault>true</activeByDefault>
- </activation>
- <properties>
- <!-- This can be a single value, or a comma-separated list -->
- <spring.profiles.to.activate>dev</spring.profiles.to.activate>
- </properties>
- </profile>
- <profile>
- <id>uat</id>
- <properties>
- <!-- This can be a single value, or a comma-separated list -->
- <spring.profiles.to.activate>uat</spring.profiles.to.activate>
- </properties>
- </profile>
- <profile>
- <id>prod</id>
- <properties>
- <!-- This can be a single value, or a comma-separated list -->
- <spring.profiles.to.activate>prod</spring.profiles.to.activate>
- </properties>
- </profile>
- </profiles>
- ...
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.6</version>
- <configuration>
- <webResources>
- <webResource>
- <filtering>true</filtering>
- <directory>src/main/webapp</directory>
- <includes>
- <include>**/web.xml</include>
- </includes>
- </webResource>
- </webResources>
- <failOnMissingWebXml>true</failOnMissingWebXml>
- </configuration>
- </plugin>
- ...
- </plugins>
- </build>
- <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Setup for root Spring context
- -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring-core-config.xml</param-value>
- </context-param>
- <!--
- Jim Tough - 2016-11-30
- Per Spring Framework guide: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-environment
- ...profiles may also be activated declaratively through the spring.profiles.active
- property which may be specified through system environment variables, JVM system
- properties, servlet context parameters in web.xml, or even as an entry in JNDI.
- -->
- <context-param>
- <param-name>spring.profiles.active</param-name>
- <param-value>${spring.profiles.to.activate}</param-value>
- </context-param>
- <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
- @Configuration
- @Profile({"dev","default"})
- @ComponentScan
- @EnableTransactionManagement
- @EnableSpringDataWebSupport
- public class PersistenceContext {
- // ...
- }
- <profile>
- <id>dev</id>
- <properties>
- <activatedProperties>dev</activatedProperties>
- </properties>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- </profile>
- <profile>
- <id>release</id>
- <properties>
- <activatedProperties>release</activatedProperties>
- </properties>
- </profile>
- <build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- …
- </build>
- spring.profiles.active=@activatedProperties@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement