Use Spring-DM Extender - java

I need to wait some time before shut down my OSGI context.( Give some time to finish the tasks that are currently running). I came across with shutdown.wait.time property in the extenderProperties bean.
Can anyone please let me know how can I use this OSGi fragments to achieve my goal? I think I can attach a fragment bundle to my existing OSGI bundle.
Thanks in advance. appreciate your help.

You'll need to create a bundle with two files in it: META-INF/MANIFEST.MF and META-INF/spring/extender/extender.xml (the xml file could be named anything with an xml extension, but must be in the META-INF/spring/extender folder). Your MANIFEST.MF file will need to contain the OSGi manifest header Fragment-Host of org.springframework.osgi.extender. If you're using the maven-bundle-plugin, your plugin configuration would look something like this:
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.5</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Fragment-Host>org.springframework.osgi.extender</Fragment-Host>
</instructions>
</configuration>
</plugin>
...
Your extender.xml file will need to define a java.util.Properties bean with a name of extenderProperties. It should contain a property named shutdown.wait.time with a value in milliseconds (eg. 30000 for 30 seconds). The file may look like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<util:properties id="extenderProperties">
<prop key="shutdown.wait.time">30000</prop>
</util:properties>
</beans>
Then deploy the bundle into your environment. You may need to restart the Spring OSGi bundles (or your server) depending on the order this fragment bundle is installed in relation to the Spring DM bundles.

Related

org.xml.sax.SAXParseException: Failed to read schema document mule-mongo.xsd in mule-domain-config

I migrate resources from different Mule Projects to one Mule Domain Project (which should be used by all the other Mule Projects). Everything works fine except the configuration for the mongodb. If I start everything and the domain starts initialization I get the following error:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd'
See the corresponding mule-domain-config.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<mule-domain
xmlns="http://www.mulesoft.org/schema/mule/domain"
xmlns:mule="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/domain http://www.mulesoft.org/schema/mule/domain/current/mule-domain.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<!-- configure here resource to be shared within the domain -->
<context:property-placeholder location="${mule.env}.properties "/>
<mongo:config name="mongoconfig" host="${mongo.host}" port="${mongo.port}" database="${mongo.database}" doc:name="Mongo DB" connectTimeout="5000" connectionsPerHost="1" autoConnectRetry="true" threadsAllowedToBlockForConnectionMultiplier="50" username="${mongo.username}">
<mongo:connection-pooling-profile maxActive="150" initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW" maxIdle="50" ></mongo:connection-pooling-profile>
<mule:reconnect frequency="1000"></mule:reconnect>
</mongo:config>
<http:listener-config name="HTTP_Listener_Configuration" host="${http.host}" port="${http.port}" doc:name="HTTP Listener Configuration"/>
</mule-domain>
My first idea was, that I need to add the mule-module-mongo dependency to the pom.xml. But this didn't change anything.
In the Mule Projects the same configuration, with the same schema declaration work just fine. Do I miss something here?
The problem is that Mongo is not supported as a shared resource so you cannot define it's config at the domain level.
You can find more information on what connectors are supported here.
HTH

Spring MVC schemas and corresponding jar files

I am new to Spring and looking for some help trying to figure what Spring schemas correspond to what jar files in my project class path. I need to know that since I am looking to upgrade to the later version of Spring. The following is the schemas I have in my xml files
in my applicationContext-dataaccess.xml
b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
in my applicationContext-resourcebundle.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
in my applicationContext-security.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
in my app-servlet.xml
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
The following is the Spring jar files I see in the class path of my project
\WEB-INF\lib\spring-xml-2.0.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.aop-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.asm-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.beans-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.context.support-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.context-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.core-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.expression-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.jdbc-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.transaction-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.web.servlet-3.1.2.RELEASE.jar"
\WEB-INF\lib\org.springframework.web-3.1.2.RELEASE.jar"
\WEB-INF\lib\spring-security-acl-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-config-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-core-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-taglibs-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-security-web-3.0.5.RELEASE.jar"
\WEB-INF\lib\spring-ws-core-2.0.2.RELEASE.jar"
\WEB-INF\lib\spring-ws-security-2.0.2.RELEASE.jar"
\WEB-INF\lib\spring-ws-support-2.0.2.RELEASE.jar"
What would be the best approach to upgrade to a later version of Spring ?Take the version names out of the schemas and just copy jar files into the class path of my project? What Spring jar files do I need for my project?
Thank you in advance for any information about this!
Take the version names out of the schemas and just copy jar files into the class path of my project?
Yes. By removing the versions from the files, the schemas will be searched and found in the jar files, since spring is stripping the schema version when building the jars. This way if your dependencies are correct, your configuration XML will be validated against the proper schemas
With the build tool. For what concerns your first and the third question. Using a proper build-managment tool, and using it properly is your best choice, the following answer can illustrate a maven based approach that gives you most flexibility when upgrading.
Without the build tool. On the other hand if you can't use any build tool, there's a dedicated github page explaining how to proceed
Although it is strongly recommended that Spring Framework users take
advantage of the transitive dependency management features of build
systems like Gradle, Maven, and Ivy, some teams cannot use these
tools. This is usually due to corporate restrictions or working with
legacy builds. If you're in this boat, you may want to build a Spring
Framework distribution zip that contains all optional and required
runtime dependencies.

Spring expression in xml configuration file

It is useful to have different property sets for different users.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:/path/to/package/default.properties,
classpath:/path/to/package/#{ systemProperties['user.name'] }.properties"/>
</beans>
When executing the application, spring does not recognize the expression. The context does not start and spring says: class path resource [path/to/package/#{ systemProperties['user.name'] }.properties] cannot be opened
When I replace the expression manually with a string resulting in a valid resource then the behaviour is as expected. The manual states it should work.
The spring-context and spring-core (3.1.2-RELEASE) are in classpath.
How come spring does not pick up the environment variable?
I'm open to alternate solutions solving the same functional problem.
SpEL expressions are not allowed there; you can do what you want indirectly, though...
<context:property-placeholder properties-ref="props"/>
<util:properties id="props" location="classpath:#{systemProperties['foo']}"/>
Here is the complete answer to the question. Keeping the override of user properties over default properties. My edit of the accepted answer got rejected.
<context:property-placeholder properties-ref="springContextCongifurationProperties"
location="classpath:/path/to/package/default.properties"
local-override="true"/>
<util:properties id="springContextCongifurationProperties"
location="classpath:/path/to/package/#{ systemProperties['user.name'] }.properties"/>

cxf webservice in standalone spring application

I try to implement a webservice in an existing standalone spring application.
I configured spring:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:beans/webservice.xml" />
....
webservice.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="CheckService" class="test.ws.CheckService">
</bean>
<jaxws:endpoint
id="checkService"
implementor="#CheckService"
address="http://localhost:9000/CheckService" />
I made the configuration according to official documentation and samples from books. I get exception:
03/11/2010 09:34:12 WARN Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://cxf.apache.org/schemas/jaxws.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.warning(Unknown Source)
...
http://cxf.apache.org/schemas/jaxws.xsd is accessible from browser and I think it is well formed (official xsd).
I suspect that the problem is not related to cxf rather swing configuration related.
Thanks,
Hubidubi
This means that it could not access the url when you are running it. This happens to us when we start our struts/tiles application without internet connection first. What you can do as an alternative is download the xsd and put it somewhere where you application can read it.
and replace http://cxf.apache.org/schemas/jaxws.xsd with /path/to/file/jaxws.xsd
Could it be that you're in an environment where you need to set up a proxy to access the web?
You have set the proxy in you browser and can thus access the .xsd via browser.
You need to set up your IDE appropriately or set a system-wide proxy.
Hope I guessed right :p
Finally I figured out the resolution. I had to add appropirate dependencies to maven pom.xml.
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
for me works w/ this.
Clearing the files from the Eclipse cache fixed this problem for me.
In Eclipse preferences, I went to General > Network Connections > Cache and removed the cxf files that were causing the issue. The error went away the next time I validated the file.

Spring schemaLocation fails when there is no internet connection

I am using Spring and in application-context.xml I have the following definitions:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.xsd"
>
.....
When my internet connection is lost, I cannot run my application via tomcat or jetty.
It gives:
[main] WARN org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '/spring-beans-2.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:96)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:380)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(XSDHandler.java:2541)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaWarning(XSDHandler.java:2532)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1836)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2408)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1753)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:921)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:483)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:678)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:553)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:523)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:371)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:332)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:181)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:356)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
2009-11-13 15:31:25,675 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 23 in XML document from class path resource [application-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinit........
Any suggestions how to fix it?
There is no need to use the classpath: protocol in your schemaLocation URL if the namespace is configured correctly and the XSD file is on your classpath.
Spring doc "Registering the handler and the schema" shows how it should be done.
In your case, the problem was probably that the spring-context jar on your classpath was not 2.1. That was why changing the protocol to classpath: and putting the specific 2.1 XSD in your classpath fixed the problem.
From what I've seen, there are 2 schemas defined for the main XSD contained in a spring-* jar. Once to resolve the schema URL with the version and once without it.
As an example see this part of the spring.schemas contents in spring-context-3.0.5.RELEASE.jar:
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/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd
http\://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.0.xsd
This means that (in xsi:schemaLocation)
http://www.springframework.org/schema/context/spring-context-2.5.xsd
will be validated against
org/springframework/context/config/spring-context-2.5.xsd
in the classpath.
http://www.springframework.org/schema/context/spring-context-3.0.xsd
or
http://www.springframework.org/schema/context/spring-context.xsd
will be validated against
org/springframework/context/config/spring-context-3.0.xsd
in the classpath.
http://www.springframework.org/schema/context/spring-context-2.1.xsd
is not defined so Spring will look for it using the literal URL defined in schemaLocation.
I solved it
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/context
classpath:spring-context-2.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.xsd"
>
classpath:spring-context-2.1.xsd is the key for working offline mode (no internet connection). Also i copied spring-context-2.1.xsd near (same directory) the application-context.xml file
Something like this worked for me.
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
classpath:org/springframework/beans/factory/xml/spring-context-3.0.xsd"
In case anyone arrives here via the same root I did - I hit this problem because I was building a single JAR with all dependencies, including Spring JARs. As a result the spring.schemas file in some of the META-INF directories of Spring JARs was overwritten.
I found suggested solutions here: How to create spring-based executable jar with maven?
Ran into a similar issue today. In my case, it was the shade plugin that was the culprit, in addition to springframework.org having an outage. The following snippet cleared things up:
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
HTH someone
You should check that the spring.handlers and spring.schemas files are on the classpath and have the right content.
This can be done with ClassLoader.getResource(..). You can run the method with a remote debugger in the runtime environment. The extensible XML authoring setup is described in the Spring Reference B.5. Registering the handler and the schema.
Normally, the files should be in the spring jar (springframework.jar/META-INF/) and on the classpath when Spring can be initiated.
Find class path
If you are using eclipse click on corresponding jar file. Goto ->META-INF-> open file spring.schemas
you will see the lines something like below.
http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.1.xsd
copy after = and configure beans something like below.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit classpath:org/springframework/amqp/rabbit/config/spring-rabbit-1.1.xsd
http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http://www.springframework.org/schema/context classpath:org/springframework/context/config/spring-context-3.1.xsd
http://www.springframework.org/schema/util classpath:org/springframework/beans/factory/xml/spring-util-3.1.xsd">
You need to add schema locations to your bean definition, and then they can be found in classpath instead of fetched over the net. Given your formatting problems, I'm not 100% sure that you aren't doing this already.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- empty: the beans we use are in the base class's context. -->
</beans>
We solved the problem doing this:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false); // This avoid to search schema online
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "TransactionMessage_v1.0.xsd");
Please note that our application is a Java standalone offline app.
If you are using eclipse for your development , it helps if you install STS plugin for Eclipse [ from the marketPlace for the specific version of eclipse .
Now When you try to create a new configuration file in a folder(normally resources) inside the project , the options would have a "Spring Folder" and you can choose a "Spring Bean Definition File " option
Spring > Spring Bean Configuation File .
With this option selected , when you follow steps , it asks you to select for namespaces and the specific versions :
And so the possibility of having a non-existent jar Or old version can be eliminated .
Would have posted images as well , but my reputation is pretty low.. :(
I would like to add some additional aspect of this discussion. In windows OS I have observed that when a jar file containing schema is stored in a directory whose path contains a space character, for instance like in the following example
"c:\Program Files\myApp\spring-beans-4.0.2.RELEASE.jar"
then specifying schema location URL in the following way is not sufficient when you are developing some standalone application that should work also offline
<beans
xsi:schemaLocation="
http://www.springframework.org/schema/beans org/springframework/beans/factory/xml/spring-beans-2.0.xsd"
/>
I have learned that result of such schema location URL resolution is a file which has a path like the following
"c:\Program%20Files\myApp\spring-beans-4.0.2.RELEASE.jar"
When I started my application from some other directory which didn't contain space character on its path then schema location resolution worked fine. Maybe somebody faced similar problems? Nevertheless I discoverd that classpath protocol works fine in my case
<beans
xsi:schemaLocation="
http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-2.0.xsd"
/>
The problem lies in the JAR files that you use in your application.
What I did, which worked, was to get inside the JARs for SPRING-CORE, SPRING-BEANS, SPRING-CONTEXT, SPRING-TX that match the version I am using. Within the META-INF folder, I concatenated all the spring.handlers and spring.schemas that come in those JARs.
I killed two birds with one stone, I solved the problem of the schemas so this also works correctly in offline mode.
P.S. I tried the maven plugin for SHADE and the transformers but that did not work.
I had this problem. For posterity, my exception was:
org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 117;
schema_reference.4: Failed to read schema document
'http://www.springframework.org/schema/beans/spring-beans-4.2.xsd'
I solved it when I realised the the version of spring-beans specified in my Maven pom.xml was 4.1.x, thus meaning the specific .xsd could not be found on the classpath.
This was masked for a long time because I normally am online, so I thought being offline had "broken" the build. But it really had nothing to do with it. Updating my pom.xml to specify the correct version of spring-beans, namely 4.2.x, fixed it.
I had the same problem when I'm using spring-context version 4.0.6 and
spring-security version 4.1.0.
When changing spring-security version to 4.0.4 (because 4.0.6 of spring-security not available) in my pom and security xml-->schemaLocation, it gets compiled without internet.
So that mean you can also solve this by:
changing spring-security to a older or same version than
spring-context.
changing spring-context to a newer or same version than
spring-security.
(any way spring-context to be newer or same version to spring-security)
I had ran into this similar problem as well. In my case, my resolution is quite different. Here's my spring context xml file:
...
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
...
I'm not specifying any xsd version as I want spring to use the latest xsd version inside spring dependencies. The spring version my application used was spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE and when I assembly my application into jar, all spring dependencies exist in my classpath. However, I received following error during startup of my spring application context:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
After some hard time troubleshooting, I found the issue is due to the index.list inside the META-INF folder of my jar file. With index.list file, spring namespace handlers cannot be located to parse the spring application context xml correctly. You can read more about this spring issue SPR-5705
By removing indexing from my maven-jar-plugin, I manage to resolve the issue. Hope this will save some times for people having the same problem.
Just make sure the relevant spring jar file are in your runtime classpath. In my case this we were missing spring-tx-4.3.4.RELEASE.jar from runtime classpath. After adding this jar, the issue was resolved.
If there is no internet connection in your platform and you use Eclipse, follow these steps (it solves my problem)
Find the exact xsd files (You can unzip these files from their jars. For example, spring-beans-x.y.xsd in spring-beans-x.y.z.RELEASE.jar)
Add these xsd files to Eclipse XML Catalog. (Preferences->XML->XML Catalog, Add files)
Add these files location to configuration file. (Be careful, write the exact version of file)
Example:
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-x.y.xsd "
Remove jars you added recently in the web-inf ->lib. for example jstl jars.

Categories

Resources