A help with Spring Boot Annotations

Asked

Viewed 94 times

2

A help with Annotations ... Today my tests are like this :

@ConfigA
@ConfigB
@ConfigC
@ConfigD
public class MeuTesteA {}

@ConfigA
@ConfigB
@ConfigC
@ConfigD
public class MeuTesteB {}

See, I have to repeat many configuration Annotations. To solve, I created an abstract class, getting this way :

@ConfigA
@ConfigB
@ConfigC
@ConfigD
public abstract class ConfigTeste {}

And the tests went like this. At this point, it works perfectly!

public class MeuTesteA extends ConfigTeste {}
public class MeuTesteB extends ConfigTeste {}

But still I think it’s better. I wanted something like :

@SuperConfig
public class MeuTesteA {}

@SuperConfig
public class MeuTesteA {}

Where my custom @Superconfig Annotation would load all of the above settings. I tried to create "@Superconfig" this way :

@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ConfigA
@ConfigB
@ConfigC
@ConfigD
public @interface SuperConfig { 

}

But it didn’t work. Don’t load the settings. Know where the error is ?

PS : The confgurations are these :

@ActiveProfiles("[UM_AMBIENTE_AQUI]")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@IntegrationTest("{server.port:8000, server.address:localhost}")

I’m using Spring Boot on version 1.3.7.RELEASE

Vlw s

  • Why aren’t you loading the settings? What doesn’t appear to work?

  • I don’t know ! It simply doesn’t load the above settings when I use my custom annotation (The purpose is not to repeat code).

  • I didn’t quite understand, but I think it would be possible to parameterize a Config annotation with the other fields for example a, b,c,d. So you’d only add one note

  • Opa Weslley Barbosa blz, so they are not different fields but different settings/annotations (the ones I put at the end of the question) . I wanted to group them all into one custom note instead of extending a class as I mentioned above. ?

No answers

Browser other questions tagged

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