Spring JDO configuration parsing error - spring

I have a spring test case that annotated as following
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {"classpath:conf/allocadia-base.xml", "classpath:META-INF/jdoconfig.xml"})
my jdoconfig is
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
when I run the test I get
java.lang.IllegalStateException: Failed to load ApplicationContext
.
.
.
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4 in XML document from class path resource [META-INF/jdoconfig.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'jdoconfig'.
if I changed jdoconfig to
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_2_3.xsd">
the error is
Caused by:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for
XML schema namespace [http://java.sun.com/xml/ns/jdo/jdoconfig]
Offending resource: class path resource [META-INF/jdoconfig.xml]
I use the latest spring 3.2 and JDO 2.3-e
the application works fine when I deploy it to tomcat I'm just getting this error when trying to run the test

Your jdoconfig.xml consist incorrect url. Try this:
xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd"
Validating jdoconfig with incorrect url
How to solve validation error on xsi:noNamespaceSchemaLocation in jdoconfig.xml

Related

camel upgrade issue in spring project

I am facing issue in upgrading camel 3.7.0 to 3.15.0. I am getting below error:
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.camel.spring.xml.handler.CamelNamespaceHandler]: Unresolvable class definition; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.apache.camel.spring.xml.handler.CamelNamespaceHandler
2875Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [producer-camel-core-context.xml];
Any help is highly appreciated.
BeanDefinitionStoreException
If you use ActiveMQ 5.x that ships with Camel 1.x and you upgrade it to use Camel 2.0 you can get an exception while starting.
ERROR: java.lang.RuntimeException: Failed to execute start task. Reason:
org.springframework.beans.factory.BeanDefinitionStoreException:
Unrecognized xbean namespace mapping: http://activemq.apache.org/camel/schema/spring
The reason is basically that the XML namespace changed in Camel 2.0 as explained below.
When Camel went from an activemq subproject to a top level apache project, they changed the URIs for their xml schemas to reflect this in Camel 2.0.
To fix this, in activemq.xml change all occurrences of:
http://activemq.apache.org/camel/schema/spring
to
http://camel.apache.org/schema/spring
and
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
to
http://camel.apache.org/schema/spring/camel-spring.xsd
Refer:
(http://people.apache.org/~dkulp/camel/exception-beandefinitionstoreexception.html)

Issue with name space handler

Please help us to resolve the below issue.
The following is the issue we are facing, when we are building the interface via Maven command(mvn clean package).
Can you please try to help on this issue?
java.lang.RuntimeException:
org.mule.api.config.ConfigurationException: Configuration problem:
Failed to import bean definitions from URL location
[classpath:common-config.xml]
Offending resource: URL [file:C:/AnypointStudio/projectname/src/test/munit/new-test-suite.xml];
nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate NamespaceHandler for namespace
[http://www.mulesoft.org/schema/mule/spring-security]
Offending resource: class path resource [common-config.xml] (org.mule.api.lifecycle.InitialisationException)
at org.mule.munit.runner.mule.SuiteRunner.(SuiteRunner.java:59)
at org.mule.munit.runner.mule.SuiteRunner.(SuiteRunner.java:45)
at org.mule.munit.remote.RemoteRunner.runTestSuite(RemoteRunner.java:75)
at org.mule.munit.remote.RemoteRunner.run(RemoteRunner.java:55)
at org.mule.munit.remote.RemoteRunner.main(RemoteRunner.java:39)
Caused by: org.mule.api.config.ConfigurationException: Configuration problem: Failed to import bean definitions from URL
location
Offending resource: URL [file:/C: Projectname/new-test-suite.xml]; nested exception is
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate NamespaceHandler for namespace
[http://www.mulesoft.org/schema/mule/spring-security]
I got the solution by adding jersey dependency in pom.xml
Thanks for your time , who look into issue

Cannot find the declaration of element 'configuration' while importing log4j2.xml file in spring

I am getting the exception as -
INFO: Initializing Spring FrameworkServlet 'dispatcher' WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 3 in XML document from class path resource [log4j2.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 31; Element type "Configuration" must be declared.
ERROR Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 3 in XML document from class path resource [log4j2.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 31; Element type "Configuration" must be declared.
Below is the Spring annotation configuration -
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = "com.test.*")
#PropertySource(value = {"classpath:application.properties"})
#ImportResource("classpath:log4j2.xml")
public class AppConfig extends WebMvcConfigurerAdapter {
...
}
Below is the log4j2 xml configuration file -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration>
<Configuration status="debug">
<Properties>
<Property name="log-path">C:/logs/</Property>
</Properties>
<Appenders>
...
</Appenders>
<Loggers>
...
</Loggers>
</Configuration>
How to get rid of this error ? Is there any mistake while importing the file into the application ? Want to enable log4j2 configuration into the project. Will the xml file be automatically understood by spring or need to write some class for it ? The maven pom file does not include sax dependency. Is that a problem ?
I think that "#ImportResource("classpath:log4j2.xml")" is the problem. Please remove this line and try again.
With #ImportResource you could add some Spring-XML-Configurations. This is not for Log4J2-Configuration.
The Log4J2-Framework will search for this resources (log4j2.xml) in the classpath. Please look at: http://logging.apache.org/log4j/2.x/manual/configuration.html
You have to enable the logging-framework with Spring. Please see http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
Thanks, everyone for you answers. Was problem in the configuration file. After an hour of brainstorming I figured it out. Just changed the configuration file code and it is working fine.

How to use local xsd for EhCache with Spring

We are facing one issue about EhCache and Spring, when we point XSD file in ehcache.xml to http://ehcache.org/ehcache.xsd, everything is ok, our application can startup correct.
But our server can't access external website, so we changed XSD location to local as below, but the application can't startup with following exception (already copy ehcache.xsd to classes folder, same as ehcache.xml).
I have googled many solution, but it still can't be fixed. I need your help about this. Thank you very much.
Spring: 3.1.0
EhCache: 2.4.2
Server: Tomcat 6.0
Java : 1.6
Config:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" monitoring="autodetect" dynamicConfig="true">
Exception:
2012-11-07 16:54:42,003 WARN [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Ignored XML validation warning>
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'ehcache.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.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2440)
... more
2012-11-07 16:54:42,007 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 3 in XML document from ServletContext resource [/WEB-INF/classes/META-INF/ehcache.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
... more
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
... more
Download ehcache.xsd, put it to the same folder where is your config xml file.
modify the xml head like below, notice the classpath prefix:
<ehcache
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="classpath:ehcache.xsd">
This will work in the development and production environment.
usually I set xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd", But this can't work in a offline environment.
My Workaround is add this xsd file to absolute path, such as: c:/ehcache.xsd and point to this location in ehcache.xml.
Hope this will help someone who facing the same issue.
Still looking forward to find out other solution.
Thanks.
In my case just downloading the file from http://ehcache.org/ehcache.xsd into src/main/resources solves the problem
cd src/main/resources
wget http://ehcache.org/ehcache.xsd

Ehcache intrigation with Spring project

i am facing this error:-
ERROR: org.springframework.web.context.ContextLoader - Context
initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for
XML schema namespace [http://www.springmodules.org/schema/ehcache]
Offending resource: ServletContext resource
[/WEB-INF/spring/application-context.xml]
If any solution for this give me suggestion.
This seems to be a library issue . Check if you have the ehcache jar in your classpath . Else download it from here .

Resources