basic usage of java annotation and reflection
Spring Annotation JAXB Annotation
Java Annotation
- started java version 5
- mapping of java attrivutes
- good to use AOP (Aspect Oriented Programming)
- can be used run-time and compile-time
- java reflection enables to use in runtime environment
Built-in Annotation
- @Override
- @Deprecated
- @SuppressWarnings
- @SafeVarargs
- @FunctionalInterface
Meta Annotaions
- @Retention
- @Documented
- @Target
- @Inherited
- @Repeatable
Annotion Usage : @Retention
- RetentionPolicy
- SOURCE : just comment, Not included in the source (ex: @Override, @SupressWarnings)
- CLASS : included when compiling, ignored in VM
- RUNTIME : included when compiling, used in VM (used by java reflection)
- examples
- @Retention(RetentionPolicy.RUNTIME)
Annotation Ragne : @Target
- ElementType
- TYPE
- FILED
- METHOD
- PARAMETER
- CONSTRUCTOR
- LOCAL_VARIABLE
- ANNOTATION_TYPE
- PACKAGE
- examples
- @Target(ElemenyType.FIELD)
- @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@interface
Java Reflection
- find the attributes of class objects
Spring Framework Annotation
Dependency Injection
- @Required
- @Autowired
- @Inject
Controller
- @Controller
- @RestController
- @RequestMapping
- @PathVariable
- @RequestBody
- @RequestParam
- @ResponseBody
Data Access
- @Service
- @Repository
Leave a comment