views:

221

answers:

0

I am using Spring's MVC framework for an application I'm hosting on Google's App Engine. So far, my controllers are registered via the @Controller annotation; however, prior to getting into Spring, I evaluated ASP.net MVC 2 which requires no configuration and is based on convention. Is convention over configuration (COC) the current and preferred method in the Java community to implement MVC with Spring. Also, this may be a result of my limited knowledge so far but i noticed that i could only instantiate my Controllers the required constuctor injection if i use the COC method via the ControllerClassNameHandlerMapping. For instance the following controller bean config will fail if i use the defaultannotationhandlermapping.

    <bean id="c"
class="com.domain.TestController">
<constructor-arg ref="service" />
</bean>
<bean id="service" class="com.domain.Service" />

My com.domain.TestController controller works fine if i use ControllerClassNameHandlerMapping/COC but it results in an error when i use defaultannotationhandlermapping/Annotations.

To clarify, I can get the constructor injection to work if i add the @autwired annotation to the constructor but if i do i have to remove the @requestmapping annotation or i will get an error stating that the controller is being mapped to the url more than once. Some researching online indicates that the controllerclassnamehandlermapping is loading and mapping my controller to the url even though i have <context:annotation-config /> and <context:component-scan base-package ... /> in my config file.

Honestly, i can overcome these issues. I really just want to know which method, annotation or COC, is the better investment.