Skip to content

Instantly share code, notes, and snippets.

@ghusta
Created October 24, 2018 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ghusta/75e20ca2613e5d85965fa9d3801cce2b to your computer and use it in GitHub Desktop.
Save ghusta/75e20ca2613e5d85965fa9d3801cce2b to your computer and use it in GitHub Desktop.
Spring custom meta-annotation with redeclared attributes from meta-annotations
import org.springframework.core.annotation.AliasFor;
import org.springframework.transaction.annotation.Transactional;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta-annotation Spring.
*
* @see Transactional
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(transactionManager = "transactionManagerCustom")
public @interface TransactionalCustom {
@AliasFor(annotation = Transactional.class, attribute = "readOnly")
boolean readOnly() default false;
}
@ghusta
Copy link
Author

ghusta commented Oct 24, 2018

@TransactionalCustom is a meta-annotation for @Transactional.

The readOnly attribute from @Transactional is redeclared to allow its use directly from @TransactionalCustom.

See documentation : Spring Meta-annotations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment