Spring MVC 3: mappatura ambigua trovata
-
29-10-2019 - |
Domanda
Sto giocando con Spring MVC 3.1 e testando diverse funzionalità. Volevo verificare la seguente dichiarazione presa da @Requestmapping#value doc
If you have a single default method (without explicit path mapping), then all requests without a more specific mapped method found will be dispatched to it. If you have multiple such default methods, then the method name will be taken into account for choosing between them
Quindi ho creato il seguente controller con più metodi di gestore predefiniti.
@Controller
@RequestMapping("/book")
public class BookController {
@RequestMapping
public @ResponseBody String greet() {
return "Hi Book!";
}
@RequestMapping
public @ResponseBody String meet() {
return "Nice to meet you Book!";
}
}
Ecco la configurazione del contesto dell'applicazione Web
<beans ....>
<!-- Use @Component annotations for bean definitions -->
<context:component-scan base-package="com.botreeconsulting.lms.web"/>
<!-- Use @Controller annotations for MVC controller definitions -->
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
Ma sembra che io abbia incasinato qualcosa in quanto mi sta dando seguendo l'errore al momento della distribuzione:
java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'bookController' bean method
public java.lang.String com.botreeconsulting.lms.web.BookController.meet()
to {[/book],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'bookController' bean method
public java.lang.String com.botreeconsulting.lms.web.BookController.greet() mapped.
Ora la domanda è che questo controller modella cosa è scritto nel documento? Sento di non averlo ottenuto correttamente. Per favore guidami a modellare il controller per abbinare l'istruzione sui più gestori predefiniti.
Grazie, Amit
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow