当我尝试使用以下代码时:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({ "classpath:applicationContext.xml",
"file:WebContent/WEB-INF/spring/appServlet/servlet-context.xml" })
@ActiveProfiles("unittest")
public class PlaygroundControllerTest {
@Test
public void test() {
}
}
我遇到了以下异常:
Caused by: java.io.FileNotFoundException: ServletContext resource [/WEB-INF/tiles/tiles.xml] cannot be resolved to URL because it does not exist
at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:154)
at org.springframework.web.servlet.view.tiles2.SpringTilesApplicationContextFactory$SpringWildcardServletTilesApplicationContext.getResources(SpringTilesApplicationContextFactory.java:105)
at org.springframework.web.servlet.view.tiles2.TilesConfigurer$SpringTilesContainerFactory.getSourceURLs(TilesConfigurer.java:423)
... 49 more
这是 servlet-context.xml 中的相关磁贴配置。
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles.xml</value>
</list>
</property>
</bean>
如何让单元测试找到瓦片的配置文件(/WEB-INF/tiles/tiles.xml)?