Spring で動作するように JUnit を構成しようとしていますが、できません。私の問題は、webflow ファイルが見つからないため、実行に失敗することです。しかし、私は実際にウェブフローのものをテストしていないので、これは私には奇妙に聞こえます! コントローラーからデータベースまで始めたいと思います。だから、これは私がやっていることです
この方法でテスト クラスを作成します。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/web-application-config.xml"})
public class MyControllerToTest {
@Autowired
private MyController ctr;
@Test
....
}
クラスパスに、web-application-config.xml がある src/main/resources を挿入しました。その内容は次のとおりです。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!-- Scans for application @Components to deploy -->
<context:component-scan base-package="com.infoone.mycontrollerpackage"/>
<!-- Imports the configurations of the different infrastructure systems of the application -->
<import resource="webflow-config.xml" />
<import resource="webmvc-config.xml" />
<import resource="data-access-config.xml" />
<import resource="repository-config.xml" />
<import resource="security-config.xml" />
MyControllerToTest クラスを JUnit として実行すると、次のようになります。
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener@6419fa] to prepare test instance [com.infoone.myapp.MyControllerToTest@10036f2]
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowExecutor': Cannot resolve reference to bean 'flowRegistry' while setting bean property 'flowDefinitionLocator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowRegistry': Invocation of init method failed; nested exception is java.lang.IllegalStateException: An I/O Exception occurred resolving the flow location pattern '/**/*-flow.xml'
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowRegistry': Invocation of init method failed; nested exception is java.lang.IllegalStateException: An I/O Exception occurred resolving the flow location pattern '/**/*-flow.xml'
...
Caused by: java.lang.IllegalStateException: An I/O Exception occurred resolving the flow location pattern '/**/*-flow.xml'
...
Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/flows/] cannot be resolved to URL because it does not exist[/code]
たぶん、src/main/resources にある私の web-flow-config ファイルも必要です (私のフローは WEB-INF/flows/* / .xml にありますが、これも src/main/ に移動しようとしました)同じ結果のリソース):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:faces="http://www.springframework.org/schema/faces"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.2.xsd">
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-listeners>
<webflow:listener ref="facesContextListener"/>
<webflow:listener ref="securityFlowExecutionListener" />
<webflow:listener ref="icefacesFlowListener" />
<webflow:listener ref="myFlowListener" />
<webflow:listener ref="myExceptionListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<!-- The registry of executable flow definitions -->
<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<!-- Configures the Spring Web Flow JSF integration -->
<faces:flow-builder-services id="facesFlowBuilderServices" development="true" />
<!-- Installs a listener that creates and releases the FacesContext for each request. -->
<bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
<!-- Installs a listener to apply Spring Security authorities -->
<bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
<bean id="icefacesFlowListener" class="com.icesoft.spring.security.WebflowListener" />
<bean id="myFlowListener" class="com.infoone.myapp.spring.webflow.AutowiringFlowExecutionListener" />
<bean id="myExceptionListener" class="com.infoone.myapp.exception.MyExceptionListener" />
私は JSF と Icefaces も使用していることを考慮してください (現時点では JUnit 経由でテストしたくありません)。
ありがとうございました!