I am following this tutorial to build a basic application with Spring. It is working flawlessly as long as I follow this sub-directory structure:
└── src
└── main
└── java
└── hello
If I move my Application.java
and ScheduledTasks.java
classes out of the hello package I get the following error:
** WARNING ** : Your ApplicationContext is unlikely to start due to a `@ComponentScan` of the default package.
And a few seconds later, indeed...
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@71fa8894: startup date [Wed Jan 18 22:19:12 CET 2017]; root of context hierarchy
My question is, why do I need to put my classes into a package? What use does it have? How can I avoid this error? Do I really need to use packages if it is a really simple application?
@ComponentScan
is scanning every class in every jar in your entire classpath. This is bad.