質問

Spring MVC 3.1で遊んで、さまざまな機能をテストしています。次の声明を確認したかったのです @requestMapping#値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

そこで、複数のデフォルトハンドラーメソッドを備えたコントローラーを次のように作成しました。

@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!";
    }
}

これが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>

しかし、展開時にエラーをフォローしているので、私は何かを台無しにしたようです。

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.

さて、問題は、このコントローラーがドキュメントに記述されているものをモデル化することです。適切に手に入れなかったと感じています。複数のデフォルトのハンドラーに関するステートメントに一致するように、コントローラーをモデル化するように導いてください。

ありがとう、アミット

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top