spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.37k stars 38.04k forks source link

Add support for meta tags to annotation based context configuration [SPR-9382] #14018

Closed spring-projects-issues closed 9 years ago

spring-projects-issues commented 12 years ago

Radim Kolar opened SPR-9382 and commented

It seems that there is no way to do equivalent of including meta tags in java annotation based container configuration. Our project is using meta tags extensively for example:

<bean id="urlfilter2"
     class="org.apache.nutch.filter.TestingURLFilter" scope="prototype">
     <meta key="after" value="urlfilter1" />
     <property name="name" value="class2"></property>
</bean>

and for writing testcases, Java context configuration is preferred over XML configuration.


Affects: 3.1.1

Reference URL: http://forum.springsource.org/showthread.php?126082-Meta-tags-in-Annotation-context-configuration

spring-projects-issues commented 12 years ago

Radim Kolar commented

Add anotation like @Meta(name="xxx", value="xxx")

spring-projects-issues commented 12 years ago

Chris Beams commented

Hi Radim,

It's interesting that you're the first (to my recollection) to request @Meta support since we've introduced annotation-based configuration some years ago. We actually did include a @Meta annotation in the standalone "JavaConfig" project, but decided not to include this support when that work was ported to the core framework in Spring 3.0. So far, that seems to have been a good decision, because no one has asked for it!

I'm putting this in the General Backlog for now, meaning that it's a totally reasonable idea, but doesn't have much priority at the moment basically because there's very little demand. If folks vote this up and add comments about their use cases, of course we'll reconsider.

If you're feeling a bit more ambitious, feel free to take a shot at implementing this support yourself. You can see how to do this in the contributor guidelines document. Keep in mind a few things:

@Metadata(
    @Meta(key="k1", value="v1"),
    @Meta(key="k2", value="v2"))
@Bean
public MyBean myBean() { ... }

You might look to the implementation of the @Primary annotation for inspiration. It behaves just like the primary attribute in XML.