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

Pav*_*nko 6 java websphere spring

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

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:by/example/**/*-ctx.xml</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

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

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

applicationContext.getResource("classpath*:by/example/**/I-*.sql").getUrl()
Run Code Online (Sandbox Code Playgroud)

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

 applicationContext.getResource("wsjar:classpath*:by/example/**/I-*.sql").getUrl()
Run Code Online (Sandbox Code Playgroud)

它运作良好.但我需要创建通用系统来在不同的应用服务器和servlet容器上加载资源.在tomcat前缀不需要.

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

Saj*_*ran -1

尝试这样的事情。

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

    Resource resource = 
       appContext.getResource("classpath*:by/example/**/I-*.sql");
Run Code Online (Sandbox Code Playgroud)

  • 问题是“Resource resource = appContext.getResource("classpath*:by/example/**/I-*.sql");” 不适用于 WAS (2认同)