I use Spring 3.x MVC @Controller annotations. My servlet.xml has this entry:
<context:component-scan base-package=”com.my.controllers.package”/>
My webapp, on Google's app engine has to initialize & startup within 60secs. Mine takes longer due to this classpath scanning (This link explains the importance of "Reducing or Avoiding the Use of Component Scanning" in app engine).
I added the following line to my servlet.xml
<bean id=”myComponentBean” class=”org.foo.MyComponent”/>
Now, regardless of whether I add @Controller or not, the controller does not get loaded. Any url results in 404.
Questions:
1) So how do I make a spring 3.x MVC controller behave as a web controller without relying on the comonent scanning?
2) When I filed a bug with google, I was asked to remove the "component scanning" & to "explicitly define the classes needed using classLoader.getResource()". How can I use classLoader.getResource() to load mvc controllers?
P.S: Classpath scanning on app engine has known issues. Discussing that will be a digression here. So I skipped the details.
you are already doing it right. define your controllers with <bean class="..." />
and put <mvc:annotation-driven />
in your servlet configuration. that is it!
UPDATE:
and you may need <context:annotation-config />
as well for some annotations(@EJB
, @PersistenceContext
, etc.) to get handled by spring.