在Springsphere应用程序服务器中按Spring加载资源

时间:2012-02-17 13:22:12

标签: java spring websphere

我在websphere应用服务器8(WAS)上运行了一个Web应用程序。在web.xml中我有:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:by/example/**/*-ctx.xml</param-value>
</context-param>

然后当我在WAS上部署我的应用程序时 - 它通过前缀为“wsjar:file ...”的网址加载我的所有ctx文件,这很好。

但是当我在我的工作应用程序中时,我尝试使用我的应用程序上下文的对象来加载这样的资源:

applicationContext.getResource("classpath*:by/example/**/I-*.sql").getUrl()

它抛出了url不正确的异常 - 但如果我添加预加“wsjar:”,就像这样:

 applicationContext.getResource("wsjar:classpath*:by/example/**/I-*.sql").getUrl()

效果很好。但我需要创建通用系统来在不同的应用服务器和servlet容器上加载资源。在tomcat中不需要前缀。

如何通过ContextLoaderListener以与ContextLoader相同的方式在WAS上加载我的应用程序中的资源加载我的ctx文件而不预加“wsjar:”?

2 个答案:

答案 0 :(得分:1)

当我使用完整的软件包名称时,我对IBM WAS没有任何问题。像这样:

            classpath:com/tdp/abc/facilitador/boost/config/reglaBoostWS-support.xml         

我没有尝试使用asteriks来指向多个文件。也许列出所有个人文件可以为你工作。

答案 1 :(得分:-1)

尝试这样的事情。

        ApplicationContext appContext = 
       new ClassPathXmlApplicationContext(new String[] {"If-you-have-any.xml"});

    Resource resource = 
       appContext.getResource("classpath*:by/example/**/I-*.sql");