サービスレイヤーとビューレイヤーのコンテキスト構成の間に明確な抽象化があり、以下に示すようにそれらをロードしています。
Root application context:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
Web application context:
<servlet>
<servlet-name>lovemytasks</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/mmapp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
現在、アプリケーションをテストするために SPRING MVC TEST FRAMEWORK を導入しようとしています。
このためには、実際の Web アプリケーションが動作するのと同じ環境をセットアップする必要があります。
どうやってやるの ?
テストで以下の構成を試して、両方のコンテキストをロードしました。
@ContextConfiguration(locations = { "classpath*:META-INF/spring/applicationContext*.xml",
"file:src/main/webapp/WEB-INF/spring/mmapp-servlet.xml" })
しかし、そのエラーは言っています
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Duplicate <global-method-security> detected.
ルート アプリケーション コンテキストと Web アプリケーション コンテキストの両方でグローバル セキュリティを定義しました。
注: Web アプリケーションを実行しても、上記の問題は発生しません。Spring MVc テストを実行したときにのみ発生します
グローバル セキュリティと 1 つの場所を削除してから、テストの実行時に変換サービスでエラーが発生しました。これは、実際の Spring アプリケーションのようにコンテキストをロードしていないことを警告しました。
ここで、Spring Web アプリケーション環境と同じように使用または動作するように、Spring MVC テスト環境をセットアップしたいと思います。どうすればそれを達成できるか教えてください。