-
30. Re: Spring Component Auto Detection
alesj Apr 29, 2009 6:58 AM (in response to zithuba)Great, thanks for the info!
Marius, can you please look at how we can use this?
Or how to apply David's fixes to our code. -
31. Re: Spring Component Auto Detection
marius.bogoevici Apr 30, 2009 8:03 AM (in response to zithuba)David,
This is awesome. I added a fix in pretty much the same vein
(subclassing XmlWebApplicationContext, deferring to VFS-based resource pattern resolution), although there are some differences in the actual implementation. Our goal is to support:
- pattern-based resource resolution
- classpath-scanning for bean instantiation
The implementation is at:
https://anonsvn.jboss.org/repos/jbossas/projects/spring-int/trunk/deployers/src/main/java/org/jboss/spring/factory/VFSXmlWebApplicationContext.java
For making sure that what we have there is dealing with all the aspects of the problem, could you give it a try and see that it works for you?
I will take a look at your fixes for pattern resolution and try to incorporate them in what we already have. Would it be possible for you to describe the issues that you encountered and maybe provide a patch for VFSResourcePatternResolver?
Thanks,
Marius -
32. Re: Spring Component Auto Detection
marius.bogoevici May 7, 2009 2:41 PM (in response to zithuba)David,
I added your fixes for scanning directories to VFSResourcePatternResolvingHelper.
Also, as a note: JBossEnabledResourcePatternResolver will work with Spring 2.5.5, but will have problems on 2.5.6 (because vfszip resources are now assumed to be jars).
So, for achieving the same result in 2.5.6, you can either:
a) override doFindPathMatchingJarResources too (having both doFindPathMatching*Resources overridden will make this work with either Spring 2.5.5 or 2.5.6)
b) use VFSXmlWebApplicationContext ;)
Marius -
33. Re: Spring Component Auto Detection
trybik May 11, 2009 10:13 AM (in response to zithuba)Hello,
I am trying to make LAMS project work on JBoss 5.
Recently we started using ContextSingletonBeanFactoryLocator in Spring. So we declared in our WARs:<param-name>contextConfigLocation</param-name> <param-value>classpath:/org/lamsfoundation/lams/admin/adminApplicationContext.xml</param-value> </context-param> <context-param> <param-name>locatorFactorySelector</param-name> <param-value>classpath*:/org/lamsfoundation/lams/**/beanRefContext.xml</param-value> </context-param> <context-param> <param-name>parentContextKey</param-name> <param-value>context.central</param-value> </context-param>
Even if we add<context-param> <param-name>contextClass</param-name> <param-value>org.jboss.spring.factory.VFSXmlWebApplicationContext</param-value> </context-param>
it will not work. I guess VFSXmlWebApplicationContext is used only for contextConfigLocation parameter. For locating beanRefFactory.xml files PathMatchingResourcePatternResolver is used and it does not "understand" VFS. Is there a solution (class, parameter, workaround) to make it work?
But there is more important issue. In LAMS we have only one beanRefContext.xml, so we can get rid of the wildcards. But the file itself reads:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="context.central" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> <list> <value>/org/lamsfoundation/lams/applicationContext.xml</value> <value>/org/lamsfoundation/lams/toolApplicationContext.xml</value> <value>/org/lamsfoundation/lams/contentrepository/applicationContext.xml</value> <value>/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml</value> <value>/org/lamsfoundation/lams/learning/learningApplicationContext.xml</value> <value>classpath*:org/lamsfoundation/lams/tool/**/*pplicationContext.xml</value> <value>/org/lamsfoundation/lams/tool/mc/mcApplicationContext.xml</value> <value>/org/lamsfoundation/lams/tool/forum/forumApplicationContext.xml</value> <value>/org/lamsfoundation/lams/tool/noticeboard/nbApplicationContext.xml</value> <value>/org/lamsfoundation/lams/authoring/authoringApplicationContext.xml</value> <value>/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml</value> <value>/org/lamsfoundation/lams/workspace/workspaceApplicationContext.xml</value> <value>/org/lamsfoundation/lams/web/webApplicationContext.xml</value> <value>/org/lamsfoundation/lams/integrationContext.xml</value> <value>/org/lamsfoundation/lams/usermanagement/ldapContext.xml</value> </list> </constructor-arg> </bean> </beans>
As you can see, we use wildcards to scan for Application Context files in all of our tools. Since some tools can be deployed or not, we can not write a full, proper list of tools. Discovery by wildcards in classpath is a very useful solution for us.
But it also stopped working, same reason - VFS bug. We tried to use VFSXmlWebApplicationContext, but it does not take list of paths as a constructor argument.
Is there something similar to VFSXmlWebApplicationContext, but inheriting from ClassPathXmlApplicationContext (thus having the needed constructor) and supporting VFS?
Or maybe you know a workaround?
A quick reply would be appreciated, as we are about to start using JBoss 5 and this is one of not many issues preventing us from doing it.
Thank you,
Marcin Cieslak -
34. Re: Spring Component Auto Detection
marius.bogoevici May 11, 2009 12:06 PM (in response to zithuba)Martin,
I see what you mean. We currently have the NamedXmlApplicationContext, but that will accept a single Resource as an argument, and an XmlWebApplicationContext (or subclass thereof) won't do it in your case.
We need to factor out something to that effect. I'll add a JIRA item.
Marius -
35. Re: Spring Component Auto Detection
trybik May 12, 2009 11:19 PM (in response to zithuba)Thank you, Marius.
Once you add a JIRA, please let me know the link, so I can track it (and vote for it!)
I hope a good solution can be found for GA version of JBoss 5 or preferably earlier.
Marcin -
36. Re: Spring Component Auto Detection
marius.bogoevici May 14, 2009 5:16 PM (in response to zithuba)Marcin,
I added VFSClassPathXmlApplicationContext. Please give it a try.
Marius -
37. Re: Spring Component Auto Detection
trybik May 18, 2009 7:23 AM (in response to zithuba)Tried it, works fine! Thank you, Marius!
There is still one thing pending, though. It is not something I need, but it might be an issue for someone else.
I am talking about scanning for beanRefContext.xml files - see my post on Mon May 11, 2009 10:13 AM.
As I mentioned, I do not need it, since LAMS has currently only one such file and I can give the path explicitly. But one of the features of ContextSingletonBeanFactoryLocator is that it can merge several such files and create contexts based on the result. This can be very useful in some cases.
Right now PathMatchingResourcePatternResolver is used and it causes errors. I am guessing that VFSResourcePatternResolver should be used, but is there a way to make Spring do it? Something similar to "contextClass" parameter?
I tried to set contextClass to VFSClassPathXmlApplicationContex and, as expected, it did not work.
Marcin -
38. Re: Spring Component Auto Detection
marius.bogoevici May 19, 2009 10:36 AM (in response to zithuba)Marcin,
Yes, that is correct. Unfortunately, ContextSingletonBeanFactoryLocator uses a ClassPathXmlApplicationContext internally.
For having the whole functionality working properly we'll need another locator class.
Marius -
39. Re: Spring Component Auto Detection
macktheknife73 Jun 22, 2009 8:02 AM (in response to zithuba)Hi ...
I'm a bit of a noob w.r.t. alot of this so apologies if this question is obvious or silly.
I've been trying to get a simple sample application running with JBoss 5.0 and Spring 2.5.6. I have used the fix provided in https://jira.jboss.org/jira/browse/JBSPRING-4 and my Root WebApplicationContext is started and created correctly using VFSXmlWebApplicationContext.
However when it tries to create the servlet it reverts back to XmlWebApplicationContext and I get afore mentioned FileNotFoundException.
Any help would be greatly appreciated !
web.xml<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextClass</param-name> <param-value>org.jboss.spring.factory.VFSXmlWebApplicationContext</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext*.xml </param-value> </context-param> <servlet> <servlet-name>amartus</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>amartus</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet> <servlet-name>service</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>service</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Trace ...
12:41:04,162 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [ContextLoader] - <Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]>
12:41:04,162 INFO [STDOUT] 22-Jun-2009 12:41:04 INFO [ContextLoader] - <Root WebApplicationContext: initialization completed in 6915 ms>
12:41:04,193 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [DispatcherServlet] - <Initializing servlet 'amartus'>
12:41:04,215 INFO [spring]] Initializing Spring FrameworkServlet 'amartus'
12:41:04,215 INFO [STDOUT] 22-Jun-2009 12:41:04 INFO [DispatcherServlet] - <FrameworkServlet 'amartus': initialization started>
12:41:04,216 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [DispatcherServlet] - <Servlet with name 'amartus' will try to create custom WebApplicationContext context of class 'org.springframework.web.context.support.XmlWebApplicationContext', using parent context [org.jboss.spring.factory.VFSXmlWebApplicationContext@185fdbe: display name [Root WebApplicationContext]; startup date [Mon Jun 22 12:40:57 BST 2009]; root of context hierarchy]>
12:41:04,221 INFO [STDOUT] 22-Jun-2009 12:41:04 INFO [XmlWebApplicationContext] - <Refreshing org.springframework.web.context.support.XmlWebApplicationContext@9a34a0: display name [WebApplicationContext for namespace 'amartus-servlet']; startup date [Mon Jun 22 12:41:04 BST 2009]; parent: org.jboss.spring.factory.VFSXmlWebApplicationContext@185fdbe>
12:41:04,222 INFO [STDOUT] 22-Jun-2009 12:41:04 INFO [XmlBeanDefinitionReader] - <Loading XML bean definitions from ServletContext resource [/WEB-INF/amartus-servlet.xml]>
12:41:04,225 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [DefaultDocumentLoader] - <Using JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl]>
12:41:04,227 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [PluggableSchemaResolver] - <Loading schema mappings from [META-INF/spring.schemas]>
12:41:04,300 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [PluggableSchemaResolver] - <Loaded schema mappings: {http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/jms/spring-jms-2.5.xsd=org/springframework/jms/config/spring-jms-2.5.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/jms/spring-jms.xsd=org/springframework/jms/config/spring-jms-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd}>
12:41:04,301 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [PluggableSchemaResolver] - <Found XML schema [http://www.springframework.org/schema/beans/spring-beans-2.5.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-2.5.xsd>
12:41:04,309 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [PluggableSchemaResolver] - <Found XML schema [http://www.springframework.org/schema/context/spring-context-2.5.xsd] in classpath: org/springframework/context/config/spring-context-2.5.xsd>
12:41:04,351 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [PluggableSchemaResolver] - <Found XML schema [http://www.springframework.org/schema/aop/spring-aop-2.5.xsd] in classpath: org/springframework/aop/config/spring-aop-2.5.xsd>
12:41:04,354 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [DefaultBeanDefinitionDocumentReader] - <Loading bean definitions>
12:41:04,380 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [DefaultNamespaceHandlerResolver] - <Loaded mappings [{http://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler, http://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler, http://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler, http://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler, http://www.springframework.org/schema/jms=org.springframework.jms.config.JmsNamespaceHandler, http://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler, http://www.springframework.org/schema/tx=org.springframework.transaction.config.TxNamespaceHandler, http://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler}]>
12:41:04,401 INFO [STDOUT] 22-Jun-2009 12:41:04 DEBUG [PathMatchingResourcePatternResolver] - <Cannot search for matching files underneath URL [vfsfile:/C:/dev/jboss-5.0.0.GA/server/default/deploy/common-mgt-fw.spring/WEB-INF/classes/com/amartus/web/] because it does not correspond to a directory in the file system>
java.io.FileNotFoundException: URL [vfsfile:/C:/dev/jboss-5.0.0.GA/server/default/deploy/common-mgt-fw.spring/WEB-INF/classes/com/amartus/web/] cannot be resolved to absolute file path because it does not reside in the file system: vfsfile:/C:/dev/jboss-5.0.0.GA/server/default/deploy/common-mgt-fw.spring/WEB-INF/classes/com/amartus/web/
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:201)
at org.springframework.core.io.UrlResource.getFile(UrlResource.java:156)
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingFileResources(PathMatchingResourcePatternResolver.java:517) -
40. Re: Spring Component Auto Detection
marius.bogoevici Jun 22, 2009 10:27 AM (in response to zithuba)Mike,
What you need to do is to add a similar contextClass configuration to your DispatcherServlet. There are two application contexts that get created with your Spring application, and in your case you need to deal with both.
Marius -
41. Re: Spring Component Auto Detection
macktheknife73 Jun 22, 2009 12:55 PM (in response to zithuba)"marius.bogoevici" wrote:
Mike,
What you need to do is to add a similar contextClass configuration to your DispatcherServlet. There are two application contexts that get created with your Spring application, and in your case you need to deal with both.
Marius
Firstly Marius ... A huge amount of thanks for the quick reply, I really appreciate it.
I had pretty much guessed that from this http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/web/servlet/DispatcherServlet.htmlA web application can define any number of DispatcherServlets. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared.
In my defence I did say I was a noob ... what should be added just in case anyone else was up too late last night :-)<servlet> <servlet-name>amartus</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextClass</param-name> <param-value>org.jboss.spring.factory.VFSXmlWebApplicationContext</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
-
42. Re: Spring Component Auto Detection
marius.bogoevici Jun 22, 2009 1:45 PM (in response to zithuba)Hmm, but ... you did too much research on this for a n00b ;)
Thanks for posting the complete configuration - as a side note, we will provide shortly a release build with these libraries and some documentation on how to use them, hopefully that will make things easier.
Marius -
43. Re: Spring Component Auto Detection
marius.bogoevici Jun 24, 2009 9:39 AM (in response to zithuba)Just a heads-up: if you get the latest sources, you only need the jboss-spring-int-vfs jar, and please use:
org.jboss.spring.vfs.context.VFSXmlWebApplicationContext
A complete example is to be found here:
http://anonsvn.jboss.org/repos/jbossas/projects/spring-int/trunk/documentation/samples/web-scanning/
We'll follow by providing a set of downloadable jars shortly. -
44. Re: Spring Component Auto Detection
macktheknife73 Jun 25, 2009 5:28 AM (in response to zithuba)Hi Marius
I have another quick question, I've tried putting the new jars in the deployers dir and the jboss lib/endorsed dir but this fix only seems to work with the jars in the lib of my war. Is this expected are is it a simple JBoss classpath config issue that I don't know about.
Thanks again,
Mike.