Skip to content

Allow the use of custom PropertySource annotations in @Configuration classes [SPR-8963] #13603

Closed

Description

@spring-projects-issues

Daniel Fernández opened SPR-8963 and commented

IMHO, there is a mismatch between the configuration possibilities offered by XML and @Configuration classes in Spring 3.1, which could be fixed by allowing developers to create custom annotations that could be used in @Configuration classes (in the same way as @PropertySource) for performing pre-configured infrastructure tasks.

These annotations could perform these configuration tasks "underneath", hiding their complexities to Spring users, in the same way namespace handlers can in an XML file.

@PropertySource is the clear example to this, as it registers a PropertySource for the specified ".properties" files, but the object registered is of a specific class hard-coded into Spring's code. This avoids the possibility of creating instances of other implementations of the PropertySource interface that perform more complex processing of .properties entries.

Specifically, the jasypt project [ http://www.jasypt.org ] --of which I'm author-- defines an "encryption" XML namespace which allows developers to register an EncryptablePropertySource that performs automatic transparent decryption of properties with "encryption:encryptable-property-placeholder/", which works in a way equivalent to "context:property-placeholder/", but applying transparent decryption.

I would love to be able to offer this same easiness of configuration in @Configuration classes with an @EncryptablePropertySource annotation, but as it happens this is not possible :-(

Please, extend the @Configuration mechanism for allowing custom annotations (with their associated handlers).

Thanks.


Affects: 3.1 GA

Reference URL: http://forum.springsource.org/showthread.php?120147-Can-I-create-my-own-annotations-for-enabling-features-at-Configuration-classes

Issue Links:

Referenced from: commits a378912

5 votes, 12 watchers

Activity

  1. spring-projects-issues commented on Jan 13, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Bjorn Harvold commented

    Definitely would make my life easier

  2. spring-projects-issues commented on Apr 22, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    We could introduce a PropertySourceResolver interface that can be configured via a resolver attribute in @PropertySource annotation (similar to how @ActiveProfiles supports an ActiveProfilesResolver). If such a resolver were introduced, you could then use @PropertySource as a meta-annotation on your custom composed @EncryptablePropertySource annotation.

    Does that sound like what you're looking for?

  3. spring-projects-issues commented on Apr 22, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Daniel Fernández commented

    Would that mean that I'd have to provide an implementation of that PropertySourceResolver interface, or would a default implementation already exist that looks for all the annotations meta-annotated with @PropertySource?

  4. spring-projects-issues commented on Aug 13, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Would that mean that I'd have to provide an implementation of that PropertySourceResolver interface, or would a default implementation already exist that looks for all the annotations meta-annotated with @PropertySource?

    Yes, if we introduce a PropertySourceResolver SPI you would have to provide an implementation that registers EncryptablePropertySource instances instead of ResourcePropertySource instances (which is what Spring registers behind the scenes for @PropertySource).

  5. spring-projects-issues commented on Feb 22, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've introduced a PropertySourceFactory strategy interface in core.io.support, with the following signature:

    PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException

    The default implementation simply builds standard ResourcePropertySource wrappers.

    @PropertySource allows for specifying factory=MyPropertySourceFactory.class now, in particular for meta-annotation purposes.

    Juergen

  6. spring-projects-issues commented on Feb 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Marten Deinum commented

    This would also fix #16732 which is more or less a duplicate of this one.

  7. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions