Announcement Announcement Module
Collapse
No announcement yet.
DispatcherServlet spring.profiles.active init-param Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DispatcherServlet spring.profiles.active init-param

    Hi,

    I've defined two beans
    HTML Code:
    <beans profile="dev">
        <jdbc:embedded-database id="dataSource" type="H2">
            ...
        </jdbc:embedded-database>
    </beans>
    
    <beans profile="prod">
        <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource"/>
    </beans>
    To enable a profile I've the following in my web.xml file (http://blog.springsource.com/2011/02...-1-m1-released)
    HTML Code:
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <init-param>
            <param-name>spring.profiles.active</param-name>
            <param-value>dev</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    When I run my app I see the following in the console
    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/data.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
    Apparently it doesn't take the spring.profiles.active param
    Any ideas how to solve this ?


    Tim

  • #2
    Are you sure you are running Spring 3.1? Spring bean profiles is available as of version 3.1. By this time maybe you have solved the issue.

    Comment


    • #3
      This seems to be a common problem, per my experience and this post http://blog.wookets.com/2011/11/spri...t-profile.html
      You can use JVM args or system properties instead, read that page.

      This may be the explanation:
      http://forum.springsource.org/showth...-init-param-gt

      Comment

      Working...
      X