Skip to content

@Value cannot be used as aliased meta-annotation [SPR-13603] #18181

Closed
@spring-projects-issues

Description

@spring-projects-issues

Jose Antonio Iñigo opened SPR-13603 and commented

It would be nice to be able to use @Value as meta annotation:

Having a properties file and the necessary context:properties-placeholder configuration...

someproperty=somevalue

In a Spring bean we could have:

@Value("${someproperty}")
private String someProperty;

Where someProperty's value would be "somevalue".

I want to create a new annotation @Refreshable with @Value as meta-annotation so that it behaves the same as using @Value directly. Since @Value requires a value I hardcode "default" hoping that @Refreshable's value() will override it:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Value("default")
public @interface Refreshable {
    String value();
}

Then when I use the new annotation in a bean, I was expecting it to work properly, injecting the declared value "somevalue", but it doesn't, I get "default".

@Refreshable("${someproperty}")
private String someProperty;

Reference URL: http://stackoverflow.com/questions/32964391/annotation-with-spring-value-meta-annotation-not-injecting-the-value

Issue Links:

Referenced from: commits 4f95593

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions