Default profile in Spring 3.1

前端 未结 7 1018
执笔经年
执笔经年 2020-11-28 19:56

In my application I have beans annotated with @Profile(\"prod\") and @Profile(\"demo\"). The first one, as you can guess :), is used on beans that

相关标签:
7条回答
  • 2020-11-28 20:46

    You can setup your web.xml as filtered resource and have this value filled by maven from maven profile settings - that what we do.

    in pom filter all resources (you can do taht if you have no ${} marking in them)

    <webResources>
        <resource>
            <directory>src/main/webapp</directory>
            <filtering>true</filtering>
        </resource>
    </webResources>
    

    in web.xml put

    <context-param>
         <param-name>spring.profiles.active</param-name>
         <param-value>${spring.prfile}</param-value>
    </context-param>
    

    in pom create maven profiles

    <profiles>
        <profile>
            <id>DEFAULT</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <spring.profile>prod</spring.profile>
            </properties>
        <profile>
        <profile>
            <id>DEMO</id>
            <properties>
                <spring.profile>demo</spring.profile>
            </properties>
        <profile>
    </profiles>
    

    Now you can use

    mvn jetty:run -P DEMO
    

    or simply -P DEMO with any maven command

    0 讨论(0)
提交回复
热议问题