1

I'm trying to create following spring configuration

<beans profile="profile1">
    <jms:outbound-channel-adapter id="sampleId"/>
</beans>

<beans profile="profile2">
    <jms:outbound-channel-adapter id="sampleId"/>
</beans>

(jms:outbound-channel-adapter is namespace from spring integration)

When create such context I get duplicated bean ids exception...

Any idea why?

edit.. (active profile is set to profile1)

Machu
  • 69
  • 5

2 Answers2

0

You have to provide an active profile for current context. This token can be set as:
an Environment Variable
a JVM Property
Web Parameter
Programmatic
Spring also looks for the token, spring.profiles.default, which can be used to set the default profile(s) if none are specified with spring.profiles.active.

Example:

<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>

where applicationContext looks like:

<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>
Anshu
  • 7,783
  • 5
  • 31
  • 41
  • 1
    Hmmm I've seen something similar but in my case with ActiveMQ schema e.g. org.springframework.web.context.ContextLoader: Context initialization failed org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 179 in XML document from class path resource [au/gov/dha/messagecentre/messagecentre-jms.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 179; columnNumber: 129; cvc-id.2: There are multiple occurrences of ID value 'messageCentreBroker'. This is with amq: schema inside beans: – Wayne Earnshaw May 31 '13 at 00:07
0

Make sure all relevant xsd declarations are using >= 3.1 versions. Profiles feature was added in Spring version 3.1. At a minimum set for beans and jms namespaces. See also my answer to a similar SO question here.

Community
  • 1
  • 1
Stephen Hartley
  • 945
  • 1
  • 11
  • 17