0

私のテストは次のようになります

public class ITCache extends AbstractIntegrationTest {
    @Test
    public void readCache() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        assertNotNull(applicationContext);
        final SimpleCacheManager simpleCacheManager = (SimpleCacheManager) applicationContext.getBean("cacheManager");
        System.out.println("cacheName:" + simpleCacheManager.getCacheNames().toString());
        System.out.println(simpleCacheManager.getCache("genders").toString());
    }
}

プラグインを使用してプロジェクトをデプロイしmaven-cargo、コンテンツを表示して見つけることもできapplicationContext.xmlます

➜  comma git:(S120297) ✗ jar -tvf integration/target/cargo/configurations/tomcat7x/webapps/common.war | grep app
  2342 Wed Jul 16 20:28:32 PDT 2014 WEB-INF/classes/applicationContext.xml
➜  comma git:(S120297) ✗  

しかし、テストを実行すると、失敗が次のように表示されます

Tests in error: 
  readCache(com.org.comma.integration.ITCache): IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist  

また、テストに次のように注釈を付けてみました

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration (locations = "classpath*:/applicationContext*.xml")
public class ITCache extends AbstractIntegrationTest {  

しかし、まだ同じ問題

ここで何がうまくいかないのですか?

更新
Myweb.xmlには次のようなエントリがあります

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
4

1 に答える 1

0

エラーが言ったように、ファイルがクラスパスに見つかりません。ファイルがクラスパスのルートにあることを確認してください。applicationContextファイルをリソースフォルダーに追加して、インストールを開始できます。私は同じコードを持っていて、それはうまくいきます.web.xmlはテストの起動とは何の関係もありません.他のことは、テストを起動する方法が重要です.Mavenをスローするか、Eclipseで直接実行できます. Maven でテストを起動すると、他の方法とは異なり、リソースが生成されます。

于 2014-07-17T19:31:39.583 に答える