Q:

Spring: What happens when we move @ComponentScan to another class in the package?

I have the following classes:
@ComponentScan
public class CDPlayerConfig {

    @Autowired
    private static CompactDisc cd;

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(CDPlayerConfig.class);
        CompactDisc cd = context.getBean(CompactDisc.class);
        System.out.println(cd);
    }
}

public interface CompactDisc {
    void play();
}

@Component
public class SgtPeppers implements CompactDisc {

    public void play() {
        System.out.println("play song....");
    }
}

When I run the class CDPlayerConfig, the program runs successfully. However, if I remove the ComponentScan annotation to CompactDisc interface or SgtPeppers I get the following error:

Exception in thread "main"
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No
  qualifying bean of type 'CompactDisc' available

I think that ComponentScan annotation marks the package where Spring looks for beans. CDPlayerConfig, CompactDisc and SgtPeppers are all placed in the same package, so allegedly moving ComponentScan annotation from one class to another should not make a difference. 
If so, why do I get an error? 

A:

For @ComponentScan to work you have to "tell" spring where to search, or it must find it with help of other, already loaded, @ComponentScan annotated class (your class must be then annotated also with @Component, @Configuration etc. so it could be found).
In your case, you register application context in the first line of main method - you have specified there to load CDPlayerConfig.class which is @ComponentScan annotated so now spring can automatically find other beans in the package:
ApplicationContext context = 
            new AnnotationConfigApplicationContext(CDPlayerConfig.class);

If you want to move @ComponentScan to another class, you have to change class registered in AnnotationConfigApplicationContext to some @ComponentScan annotated class:
SgtPeppers:
@Component
@ComponentScan
public class SgtPeppers implements CompactDisc {
(...)

Main in CDPlayerConfig:
ApplicationContext context = 
            new AnnotationConfigApplicationContext(SgtPeppers.class);

Note you should register context from concrete classes (not interfaces).
Also, above sample would work even without @ComponentScan annotation on SgtPeppers, but then beans defined in other classes from the package wouldn't be found.

