== Why is this an issue?

``++@ComponentScan++`` is used to determine which Spring Beans are available in the application context. The packages to scan can be configured thanks to the ``++basePackageClasses++`` or ``++basePackages++`` (or its alias ``++value++``) parameters. If neither parameter is configured, ``++@ComponentScan++`` will consider only the package of the class annotated with it. When ``++@ComponentScan++`` is used on a class belonging to the default package, the entire classpath will be scanned.

This will slow-down the start-up of the application and it is likely the application will fail to start with an ``++BeanDefinitionStoreException++`` because you ended up scanning the Spring Framework package itself.


This rule raises an issue when:

* ``++@ComponentScan++``, ``++@SpringBootApplication++`` and ``++@ServletComponentScan++`` are used on a class belonging to the default package
* ``++@ComponentScan++`` is explicitly configured with the default package


=== Noncompliant code example

[source,java]
----
import org.springframework.boot.SpringApplication;

@SpringBootApplication // Noncompliant; RootBootApp is declared in the default package
public class RootBootApp {
...
}
----

[source,java]
----
@ComponentScan("")
public class Application {
...
}
----


=== Compliant solution

[source,java]
----
package hello;

import org.springframework.boot.SpringApplication;

@SpringBootApplication // Compliant; RootBootApp belongs to the "hello" package
public class RootBootApp {
...
}
----



ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Remove the annotation "@SpringBootApplication" | "@ComponentScan" or move the annotated class out of the default package.

or

Remove the annotation "@SpringBootApplication" | "@ComponentScan" or move the "XXX" class out of the default package.

or

Define packages to scan. Don't rely on the default package.


'''
== Comments And Links
(visible only on this page)

=== on 20 Apr 2018, 20:43:26 Ann Campbell wrote:
\[~alexandre.gigleux] I've made a couple small edits, but there are phrases that still need attention. 


____
@ComponentScan (and so @SpringBootApplication that is annotated with @ComponentScan) 
____


Can the parenthetical phrase be eliminated? Or clarified somehow?


____
This will not help to speed up the start-up of the application
____


Can we just say it will slow it down? Or might there actually be an expectation that startup would be faster? If so, it would be useful to elaborate on that.



=== on 21 Apr 2018, 21:01:23 Alexandre Gigleux wrote:
\[~ann.campbell.2]: Fixed

endif::env-github,rspecator-view[]
