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

import should support classpath: [SPR-671] #5399

Closed
spring-projects-issues opened this issue Jan 31, 2005 · 4 comments
Closed

import should support classpath: [SPR-671] #5399

spring-projects-issues opened this issue Jan 31, 2005 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Tim Schafer opened SPR-671 and commented

2005-01-31 13:58:49 StandardContext[/kls2]Loading root WebApplicationContext
2005-01-31 13:58:49 StandardContext[/kls2]Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/classpath:/database.beans.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classpath:/database.beans.xml]
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classpath:/database.beans.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:89)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:127)
at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.importBeanDefinitionResource(DefaultXmlBeanDefinitionParser.java:226)
at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:180)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:170)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:129)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:144)
at org.springframework.context.support.AbstractXmlApplicationContext.refreshBeanFactory(AbstractXmlApplicationContext.java:79)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:249)
at org.springframework.web.context.support.XmlWebApplicationContext.refresh(XmlWebApplicationContext.java:131)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:167)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:101)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:922)
at org.apache.catalina.manager.HTMLManagerServlet.deployInternal(HTMLManagerServlet.java:271)
at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)


Affects: 1.1.2

1 votes, 0 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The path passed into the import tag is always considered relative to the resource that loaded the file that contains the import. That's why you saw your "classpath:" prefix appended to the WEB-INF directory.

I would argue that importing from a fixed location doesn't make much sense, as it makes the main file too tied to a specific scenario. I would recommend to use a "contextConfigLocation" in web.xml in that case, linking those fixed locations together independently.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Tim Schafer commented

The use case for classpath: in import tags:

Being able to swap one service jar for another.

Both would expose the same beans for use in their context
but the wiring could be different as well as which specific classes
were being wired.

The following URL is an example that would also benefit from classpath:
syntax in the import tag.

http://opensource.atlassian.com/confluence/spring/display/DISC/Componentizing+Spring+and+Hibernate+Development?showComments=true#comments

@spring-projects-issues
Copy link
Collaborator Author

David Harkness commented

I was using the import feature for unit testing successfully because all of the contexts were duplicated and trimmed down in the test hierarchy.

Now, however, as the application is more complex, I would like to break apart the single huge context into multiple smaller ones. The reason is that in some cases I want to deploy a subset of a service's beans. I was hoping to split the context into smaller pieces and import them all into the main applicationContext.xml for the service, creating three such contexts (1 for each version of the service).

However, one such piece clearly belongs in the utilities project outside the service's project. This causes problems because the main AC cannot import the small bean context from another JAR. On top of that, now I want to reuse those smaller contexts in my unit tests (I know, don't use an XML context in unit tests, bah), but again I cannot cross classpath boundaries (build/test/.../ac.xml cannot import build/classes/.../sub.xml).

I'd settle for a good set of standard practices for how to do this. I've read most every document I can get my hands on, and so far they all give pretty much the same basics of wiring beans together. I haven't found any "architectural" documents on how to lay out the contexts and work them into unit testing or build a large application from separate services all wired together.

I can't imagine that it's preferable to list all the needed contexts in web.xml for a couple reasons:

  • What do you do for standalone applications?
  • How do you create a simple factory class that doesn't need to be handed a list of 15 contexts?
  • How do you do unit testing (arguably integration testing using JUnit)?

I really hope the books coming out shortly address these higher-level issues. It seems everything I read only recaps the nitty-gritty details.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

OK, I've added full resource loading functionality to DefaultXmlBeanBeanDefinitionParser's import handling: it supports both "classpath:" pseudo URLs and standard URLS (e.g. "file:") now and only considers a plain file path to be relative to the resource that contains the import tag.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 10, 2019
@spring-projects-issues spring-projects-issues added this to the 1.1.5 milestone Jan 10, 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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants