How to pass a parameter from one Annotation to another?

Asked

Viewed 75 times

0

How can I replace the value of @ConditionalOnExpression by the value passed in the SecurityConfig?

Current code:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@EnableWebSecurity
@Configuration
@ConditionalOnExpression("'${auth.provedor:NULL}'.equals('DEV-JWT')")
@EnableGlobalMethodSecurity(
          prePostEnabled = true, 
          securedEnabled = true, 
          jsr250Enabled = true)
public @interface SecurityConfig {
    String value();
}

Code example desired (but not working):

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@EnableWebSecurity
@Configuration
@ConditionalOnExpression(SecurityConfig.class.getValue())
@EnableGlobalMethodSecurity(
          prePostEnabled = true, 
          securedEnabled = true, 
          jsr250Enabled = true)
public @interface SecurityConfig {
    String value();
}

1 answer

0


In this case my error was very simple, I should not try to get the values in the Annotations after all are interfaces and yes in the implementation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.