简体   繁体   中英

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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM