Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Meta-Annotations

Does anybody know what Spring JAR (and where to find it!) contains the functionality for Spring's so-called "meta-annotations". As this article shows, these cool "new" (well, sorta) constructs allow code like this:

@Service
@Scope("request")
@Transactional(rollbackFor=Exception.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyService {
}

@MyService
public class RewardsService {
    …
}

Basically, I have a Swing app that does not currently use Spring. I have a sudden requirement change that would be made supremely-easier if I could use these annotations.

So I'm just looking for the smallest, minimally-invasive Spring JAR where this functionality can be found. If absolute-need-be, I can use the entire Spring JAR, but it would be a very heavy-handed solution. It would be nice if Spring released a smaller JAR with smaller-scope functionality.

I'm browswing Maven Repo and see spring-core which contains a package called:

org.springframework.core.annotation

But upon inspection of the API docs it doesn't seem to be what I need...

Ancillary question: is it even possible to use these meta-annotations as standalone constructs, or do I have to use them along with, say, Spring DI or AOP or other major parts of the Spring framework?

Thanks in advance!

like image 616
IAmYourFaja Avatar asked Jan 11 '12 21:01

IAmYourFaja


2 Answers

The annotations you want will be with the jar it is related to. For instance, the annotation org.springframework.transaction.annotation.Transactional will be in the spring-transactions artifact.

Meta-annotations are not really different from regular annotations other than the fact that Spring now detects Annotations on annotations whereas it didn't before. Whether annotations "work" or not depends on what is looking for them (in this case something in the Spring context).

For further reading see Annotation-based container configuration in the Spring framework reference.

like image 68
Dev Avatar answered Sep 27 '22 20:09

Dev


There is project on github which is trying to provide meta-annotation functionality. https://github.com/dblevins/metatypes/

like image 36
Ondrej Bozek Avatar answered Sep 27 '22 21:09

Ondrej Bozek