だから私は、Spring Beans をスコープするために見つけたガイドに従っています。
私は 3 番目のオプションを使用しています。これは、コンポーネントがセッションでスコープされ、コントローラーがリクエストでスコープされ、コンポーネントがコントローラーに自動配線されることを意味します (したがって、セッションごとに 1 つのインスタンスしかありません)。
しかし、これを行うと、Eclipseエラーが発生します:
ハンドラー 'somethingsController' を URL パス [/SomethingsPage] にマップできません: ハンドラー 'scopedTarget.somethingsController' が既にマップされています。
私のコントローラーには、次のようなメソッドがあります。
@RequestMapping(value = "SomethingsPage")
public ModelAndView changeTheSomething(HttpServletRequest request) {
[...]
}
そして、その方法をコメントアウトすると、すべてがうまく機能します。(そのメソッドを除く。)したがって、何らかの理由で、そのようなコントローラー内でリクエストマッピングを使用すると、何かが壊れます。リクエスト マッピングを変更してすべてを機能させる方法はありますか?
したがって、この問題は、スプリング xml によってコントローラーが 2 回スキャンされ、@Requestmapping が 2 回マッピングされてエラーがスローされることに関係していると考えています。クラスの注釈をスコープと自動配線の観点からどのように使用しているかを考慮して、xml ファイルの設定方法に何か問題がありますか?
<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Use @Component annotations for bean definitions -->
<context:component-scan base-package="controllers, daos, map, models, session, testControllers" scoped-proxy="targetClass" />
<!-- added this because I think it makes annotations work? -->
<context:annotation-config />
<!-- Use @Controller annotations for MVC controller definitions -->
<mvc:annotation-driven />
[... bunch of other stuff that shouldn't be relevant]