Announcement Announcement Module
Collapse
No announcement yet.
Bean Profiles using Spring 3.1.RC1 - An example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean Profiles using Spring 3.1.RC1 - An example

    This is not a question, but rather an example on how I utilized the bean profiles support for my webapp using Spring 3.1.RC1:

    I have two profiles a "web-dev" for demo purposes, and a "test-dev" for unit and integration testing. To activate the "web-dev" profile, in my web.xml, I declare the following:

    Code:
    <servlet>
    	<servlet-name>spring</servlet-name>
    	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    	<init-param>
    	<param-name>spring.profiles.active</param-name>
    	<param-value>web-dev</param-value>
    	</init-param>
    </servlet>

    Here's my applicationContext.xml. Notice the first three import xmls are both shared by test-dev and web-dev profiles:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:p="http://www.springframework.org/schema/p" 
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	   		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    	   		http://www.springframework.org/schema/context
    	   		http://www.springframework.org/schema/context/spring-context-3.1.xsd
    			http://www.springframework.org/schema/mvc 
    			http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
    			
    	<context:property-placeholder properties-ref="deployProperties" />
     
     	<!-- Import bean definitions -->
    	<beans profile="web-dev, test-dev">
    		<import resource="trace-context.xml"/>
    		<import resource="spring-data-jpa.xml"/>
    		<import resource="spring-security-roles.xml" />
    	</beans>
    	
    	<beans profile="web-dev">
    		<bean id="deployProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"
    				p:location="/WEB-INF/spring.properties" />
            
    		<import resource="spring-cache.xml"/>
    		<import resource="tiles-context.xml" />
    		<import resource="themes-context.xml" />
    	</beans>  
    	
    	<beans profile="test-dev">
    		<bean id="deployProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"
    				p:location="classpath:spring.properties" />
    	</beans>
    </beans>

  • #2
    Follow-up: I encountered a problem with this setup. Please see http://forum.springsource.org/showth...367#post383367

    Comment

    Working...
    X