Punter Vicky Punter Vicky - 1 year ago 169
Java Question

Multiple files having @EnableAutoConfiguration annotation

I saw a spring boot project which had @EnableAutoConfiguration defined in the file that main method similar to all Spring Boot projects that I have seen. However I saw this annotation being defined in other java files (file for including Swagger config) within the same project. Should this annotation be defined in multiple files? Will there be any adverse impact in doing this?

Answer Source

@EnableAutoComfiguration should only appear once.

In its simplest form, it won't cause any harm if it's declared multiple times, but there's no benefit. However, if you configure any excludes, those excludes will have to be configured on every occurrence of the annotation as they're not cumulative.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download