Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring cannot load xml files from jars when wildcards used [SPR-7198] #11857

Closed
spring-projects-issues opened this issue May 12, 2010 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Andruschuk Borislav opened SPR-7198 and commented

I use Tomcat 6.0.18 as servlet container and Spring application context cannot be loaded from jar files in unpacked WAR, i.e. when I specified context config locations in web.xml as following Spring-xml files wont be loaded:
<servlet>
<servlet-name>ApplicationServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/lib/.jar!//ac-.xml classpath*:/ac-*.xml
</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>

Spring load xml files which is only in WEB-INF/classes but miss files from WEB-INF/lib.
I've investigated that problem is in org.springframework.web.context.support.ServletContextResourcePatternResolver. I've fix this problem in my own subclass of ResourcePatternResolver and checked this fix redefining standard resolver whith my own via overriden getResourcePatternResolver method in my own implementation of XmlWebApplicationContext. Please see attached file.


Affects: 2.5.5

Attachments:

Referenced from: commits a8ed982

@spring-projects-issues
Copy link
Collaborator Author

Andruschuk Borislav commented

JIRA breaks wildcards from bug description so I've attached included part of web.xml as separate file.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I wonder why you need to specify that WEB-INF/lib jar path to begin with? Aren't files in those jars picked up by the general "classpath*:" URL already?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Andruschuk Borislav commented

it would be nice if these xml files will be loaded by general URL like classpath*: but Spring wont load it from jars when I use pattern:```
classpath*:**/ac-*.xml

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've added support for such "/WEB-INF/lib/*.jar!/**/context.xml" style patterns as of Spring 3.0.3. This will be available in tonight's 3.0.3 snapshot - feel free to give it an early try!

"classpath*:" unfortunately has a fundamental limitation in that it requires as base path to search from. For example, "classpath*:META-INF//context.xml" or "classpath*:com/mycompany//context.xml" should work fine. JVM ClassLoaders are able to resolve such base packages at runtime, for further traversal down the package hierarchy, but do not resolve classpath roots in jar files, unfortunately - which is why specifying the base package makes a difference. Going through WEB-INF/lib jar files directly, as you do, is a fine workaround for that limitation.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants