Spring Framework
  1. Spring Framework
  2. SPR-7508

Add environment abstraction and support bean definition profiles

    Details

    • Last commented by a User:
      false

      Issue Links

        Activity

        Hide
        Dave Syer added a comment - - edited

        Does anyone else except me dislike the names of the System properties used by Spring (springProfiles, defaultSpringProfile)? They are camel case, whereas the convention for java.util.Properties names is lower case and period separated (especially System properties it would seem - start a JVM and list the standard ones to see what I mean).

        Show
        Dave Syer added a comment - - edited Does anyone else except me dislike the names of the System properties used by Spring (springProfiles, defaultSpringProfile)? They are camel case, whereas the convention for java.util.Properties names is lower case and period separated (especially System properties it would seem - start a JVM and list the standard ones to see what I mean).
        Hide
        Sam Brannen added a comment - - edited

        Dave,

        I agree: we should go with the convention, not camel case.

        For example, what about something like the following?

        • springProfiles --> spring.profiles
        • defaultSpringProfile --> spring.profile.default
        Show
        Sam Brannen added a comment - - edited Dave, I agree: we should go with the convention, not camel case. For example, what about something like the following? springProfiles --> spring.profiles defaultSpringProfile --> spring.profile.default
        Hide
        Oliver Gierke added a comment -

        +1 for . notation

        Show
        Oliver Gierke added a comment - +1 for . notation
        Hide
        Chris Beams added a comment -

        Thanks all for pointing this out. Yes, obviously it should be dot notation.

        I've updated to:

        • spring.profile.active
        • spring.profile.default

        While it may be the most 'correct' approach to fully qualify here with org.springframework.profile, I'm currently thinking that saving keystrokes is worth the tradeoff. A naming collision with spring.profile.* is highly unlikely anyway.

        Currently, there may be only one default profile, but any number of active profiles may be specified. For this reason, it may be best to use a plural 'profiles' (spring.profiles.active), but (a) I dislike the asymmetry with spring.profile.default remaining singular - this makes things harder to remember and errors are more likely. (b) it's conceivable that we would allow for multiple default profiles in the future, so wouldn't want to be stuck with the singular naming. I see the choices as being:

        • spring.profile.active
        • spring.profile.default

        or

        • spring.profiles.active
        • spring.profiles.default

        Generally speaking, we use singular package names (.beans being a notable exception). This is enough to sway me into saying we should leave profile singular (as is now the case in my latest commit).

        Show
        Chris Beams added a comment - Thanks all for pointing this out. Yes, obviously it should be dot notation. I've updated to: spring.profile.active spring.profile.default While it may be the most 'correct' approach to fully qualify here with org.springframework.profile , I'm currently thinking that saving keystrokes is worth the tradeoff. A naming collision with spring.profile.* is highly unlikely anyway. Currently, there may be only one default profile, but any number of active profiles may be specified. For this reason, it may be best to use a plural 'profiles' ( spring.profiles.active ), but (a) I dislike the asymmetry with spring.profile.default remaining singular - this makes things harder to remember and errors are more likely. (b) it's conceivable that we would allow for multiple default profiles in the future, so wouldn't want to be stuck with the singular naming. I see the choices as being: spring.profile.active spring.profile.default or spring.profiles.active spring.profiles.default Generally speaking, we use singular package names ( .beans being a notable exception). This is enough to sway me into saying we should leave profile singular (as is now the case in my latest commit).
        Hide
        James Ward added a comment -

        Is there some way to set the default profiles from a Maven build? I'd like to set the default to my "dev" profile for running "mvn test" so that the developer doesn't have to remember to run "mvn -Dspring.profiles.active=dev test".

        Thanks!

        Show
        James Ward added a comment - Is there some way to set the default profiles from a Maven build? I'd like to set the default to my "dev" profile for running "mvn test" so that the developer doesn't have to remember to run "mvn -Dspring.profiles.active=dev test". Thanks!
        Hide
        Stevo Slavić added a comment -

        @James See maven surefire plugin system properties example

        e.g.

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <spring.profiles.active>test</spring.profiles.active>
            </systemPropertyVariables>
          </configuration>
        </plugin>
        
        Show
        Stevo Slavić added a comment - @James See maven surefire plugin system properties example e.g. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <systemPropertyVariables> <spring.profiles.active>test</spring.profiles.active> </systemPropertyVariables> </configuration> </plugin>
        Hide
        James Ward added a comment -

        Exactly what I needed! Tested and works great! Thanks Stevo!

        BTW: I used:
        <systemPropertyVariables>
        <spring.profiles.default>dev</spring.profiles.default>
        </systemPropertyVariables>

        Show
        James Ward added a comment - Exactly what I needed! Tested and works great! Thanks Stevo! BTW: I used: <systemPropertyVariables> <spring.profiles.default>dev</spring.profiles.default> </systemPropertyVariables>
        Show
        Chris Beams added a comment - Completed in M1; see http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/

          People

          • Assignee:
            Chris Beams
            Reporter:
            Chris Beams
            Last updater:
            Trevor Marshall
          • Votes:
            5 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 7 weeks ago