rspec/rules/S4604/java/rule.adoc

66 lines
1.7 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
"@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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
@SpringBootApplication
public class MyApplication {
...
}
----
----
@Configuration
@EnableAutoConfiguration
public class MyApplication {
...
}
----
2021-04-28 16:49:39 +02:00
== 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 {
...
}
----