Closed spring-projects-issues closed 9 years ago
Radim Kolar commented
Add anotation like
@Meta
(name="xxx", value="xxx")
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:
@Meta
should be supported at both the @Bean
method level and at the @Component
class level for feature parity between these two styles.<meta>
elements associated with a given <bean>
. To achieve this in Java, we need not only a @Meta(name="key", value="value")
, but also a "meta collection" annotation to accommodate the case of multiple @Meta
annotations. This is always a bit awkward, but would look something like the following:@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.
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:
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