org.sonar.l10n.java.rules.java.S4604.html Maven / Gradle / Ivy
This rule is deprecated, and will eventually be removed.
Why is this an issue?
"@EnableAutoConfiguration" is a convenient feature to configure the Spring Application Context by attempting to guess the beans that you are likely
to need. The drawback is that it may load and configure beans the application will never use and therefore consume more CPU and RAM than really
required. @EnableAutoConfiguration
should be configured to exclude all the beans not required by the application. Alternatively, use the
@Import
annotation instead of @EnableAutoConfiguration
, to explicitly import the useful AutoConfiguration classes.
This rule applies for @SpringBootApplication
as well.
Noncompliant code example
@SpringBootApplication
public class MyApplication {
...
}
@Configuration
@EnableAutoConfiguration
public class MyApplication {
...
}
Compliant solution
@SpringBootApplication(exclude = {
MultipartAutoConfiguration.class,
JmxAutoConfiguration.class,
})
public class MyApplication {
...
}
@Configuration
@EnableAutoConfiguration(exclude = {
MultipartAutoConfiguration.class,
JmxAutoConfiguration.class,
})
public class MyApplication {
...
}
@Configuration
@Import({
DispatcherServletAutoConfiguration.class,
EmbeddedServletContainerAutoConfiguration.class,
ErrorMvcAutoConfiguration.class,
HttpEncodingAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
JacksonAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
ThymeleafAutoConfiguration.class,
WebMvcAutoConfiguration.class
})
public class MyApplication {
...
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy