I am trying to build a stand alone Spring based Java application.
I am using Maven assembly plugin to build the JAR with dependencies. The strcture of the JAR ends up looking like this (Just a subset):
com
META-INF
org
properties
- taskexecutor.properties
spring
- properties.xml
.
.
.
Manifest looks like this:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: authorname
Build-Jdk: 1.6.0_30
Main-Class: com.company.utilities.task.TaskLauncher
When the application runs the property placeholder should be configured by including the properties.xml file:
<?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.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:property-placeholder location="classpath:/properties/taskExecutor.properties"/>
</beans>
It runs fine in Eclipse, but when I run the JAR I get this error:
Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileN
otFoundException: class path resource [properties/taskExecutor.properties] cannot be opened because it does not exist
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.company.utilities.task.TaskLauncher.main(TaskLauncher.java:28)
Caused by: java.io.FileNotFoundException: class path resource [properties/taskExecutor.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:161)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:69)
... 6 more
Any ideas?
move taskExecutor.properties to root and try it
<context:property-placeholder location="taskExecutor.properties"/>
It appears running through the command line is case sensitive but Eclipse is not when loading these resources.
Renaming taskexecutor.properties to taskExecutor.properties fixed the issue. Oops. Hopefully this helps someone equally as stupid as me in the future ;-)
Related
I have recently migrated code from spring 4 (4.1.7) to spring 5(5.1.4).
During this spring migration I have removed version numbers from project spring Xmls and this is xml schema from library i cannot update:
<?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"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"
default-lazy-init="true"
>
After upgrade getting below Exception while loading bean definitions due to library XML I have given above:
Caused by: org.xml.sax.SAXParseException; lineNumber: XX;
columnNumber: XX; : XML-24500: (Error) Can not
build schema 'http://www.springframework.org/schema/context' located
at
'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
Detailed stack trace is :
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from class path resource [xxxlib-core-spring-main.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 5; <Line 16, Column 5>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:622)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:518)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:95)
at com.xxxxxxxx.dataaccess.xxx.util.SpringHelper.init(SpringHelper.java:41)
at com.xxxxxxxx.dataaccess.xxx.util.SpringHelper.getBean(SpringHelper.java:69)
at com.xxxxxxxx.dataaccess.xxx.api.xxxAPILoader.<clinit>(xxxAPILoader.java:339)
... 30 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 5; <Line 16, Column 5>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:428)
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:290)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:425)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:242)
at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:175)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:434)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
... 46 more
Caused by: oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
at oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:1122)
at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:673)
at oracle.xml.parser.schema.XSDValidator.processSchemaLocation(XSDValidator.java:1063)
at oracle.xml.parser.schema.XSDValidator.startElement(XSDValidator.java:668)
at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1635)
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:458)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:404)
Does it mean we can move to Spring 5 only if all of our libraries
are also on spring 5 ? (I can't believe spring can introduce such problem)
Is there any workaround available for this problem ?
Am I missing some configuration due to this getting this Exception
I have come across github-issue which suggests in spring 5 version is dropped but old versions are still supported.
Edit1:
I came across another question: , since I am also using xmlparserv2-12.1.0.2.jar after using below workaround (looks like) it seems to pass this exception (XSDException: Duplicated definition for: 'identifiedType') but still not able to load bean from library, now it throws Exception org.springframework.beans.factory.NoSuchBeanDefinitionException
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
Edit2:
Above Edit1 solves my problem, bean exception was my local setup problem. I came across another good answer, it says we can not mix unversioned and versioned schemas. But in my case I can not remove version number from third party library, in this case I will have to go through solution given in Edit1, although that looks bad hack.
Is there any other better way to fix this problem ?
I'm trying to configure an ActiveMQ broker in a Spring Boot 2.1.7 application, specifically to enabled the statisticsBrokerPlugin.
My activemq.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
<amq:broker brokerName="broker1" persistent="false">
<amq:plugins>
<amq:statisticsBrokerPlugin/>
</amq:plugins>
<amq:transportConnectors>
<amq:transportConnector name="vm" uri="vm://embedded?broker.persistent=false,useShutdownHook=false"/>
</amq:transportConnectors>
</amq:broker>
<amq:connectionFactory id="jmsFactory" brokerURL="vm://embedded"/>
</beans>
integrated using
#ImportResource("classpath:activemq.xml")
in a Kotlin / Gradle application with build.gradle.kts
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-activemq")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-integration")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-configuration-processor")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(module = "junit")
}
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.1")
}
Starting the application fails with
Caused by:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://activemq.apache.org/schema/core]
Offending resource: class path resource [activemq.xml]
I'm finding a few posts regarding an issue with a Maven plugin, but nothing with Gradle.
Any ideas?
Spring requires definition of META-INF/spring.handlers when adding non-Spring configuration in XML (as described here: https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/extensible-xml.html). The META-INF/spring.handlers definition for ActiveMQ is defined in
implementation("org.apache.activemq:activemq-spring")
and this dependency is NOT added by the Spring Boot "spring-boot-starter-activemq". So adding above line in build.gradle.kts resolved the issue.
Beware that there are further issues when building a shadow JAR (=fat JAR Gradle-style), as the various META-INF/spring.** files need be merged. https://dzone.com/articles/gradle-spring-woes-issues-in-creating-single-jar-b has more on this.
Camel Configuration was working fine with v 2.13.4. After migrating to v 2.15.1 I am getting following error:
Caused by: org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.apache.camel.component.cxf.spring.NamespaceHandler] for namespace [http://camel.apache.org/schema/cxf]: problem with handler class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/apache/camel/component/cxf/spring/NamespaceHandler, offset=6
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:140)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1422)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:174)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:144)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:100)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:510)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
... 45 more
Caused by: java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/apache/camel/component/cxf/spring/NamespaceHandler, offset=6
In camel configuration I am using following schemas:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<cxf:cxfEndpoint id="soapProxy"
address="/data" endpointName="s:dataManagementSOAP"
serviceName="s:dataManagement"
wsdlURL="/path/to/proxy.wsdl"
xmlns:s="http://www.test.com/integration/referencedata" />
......
bean definitions
.....
You seem to be running your application on Java 6.0, and Apache Camel has dropped support of Java 6.0 since 2.14.0 (see "Important changes to consider when upgrading" section)
Recompiling camel in Java 6.0 wont be feasible, I believe your options are either to upgrade to Java 7.0 or to downgrade Camel to a version pre 2.14.0
I'm trying to get CXF to work with spring, maven on weblogic.the project compile/build fine, but when I try to deploy it I got this error:
<User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ibanInfos': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/ws/EndpointReference.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ibanInfos': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/ws/EndpointReference
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
Truncated. see log file for complete stacktrace
java.lang.NoClassDefFoundError: javax/xml/ws/EndpointReference
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2395)
at java.lang.Class.getDeclaredMethods(Class.java:1763)
at java.beans.Introspector$1.run(Introspector.java:1265)
at java.security.AccessController.doPrivileged(Native Method)
Any idea how to solve this?
In fact, I'm using the java first strategy to generate WSDL.
Here is my spring file :
<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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:service-definition-beans.xml"/>
<jaxws:endpoint id="ibanInfos" implementor="#ibanInfosService" address="http://localhost:7001/IbanInfos" />
</beans>
Make sure you have jaxws-api-2.3.1.jar in your classpath.
It can be download via the above link or from maven.
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
I finally found the problem : im actually using weblogic under 10.0 version which provide Jaxws2.0 that doest contain EndPointInterface.
A workaroud is to add the jar into setDomainEnv.sh and it will work perfectly. Thanks alot for your answers.
EndpointReference was introduced in JAX-WS 2.1, and JAX-WS 2.1 is included into JRE since Java 1.6.0_04.
So, if EndpointReference is unavailable in your environment you need to upgrade your JRE/JDK, or include a recent version JAX-WS API as a separate dependency.
Seems like this class is not in your classpath. You should add the relevant item to your POM.
From searching the web, this class is present in many libraries. Here is an excerpt for including such aritfact:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.3</version>
</dependency>
Looks like you are using higher version of java, for an application which is not compatible to it yet.
If you are building the app in Intellij, try changing the jdk setup to java11 or java8, this would fix the issue.
I'm using eclipse and when I try to run my spring-GWT application in development mode I get the following Exception when parsing the applicationContext.xml file:
Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx-3.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)
(...)
Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 51 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
And my applicationContext.xml file starts like this:
<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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
(...)
Line 51 ---> <tx:annotation-driven transaction-manager="transactionManager"/>
Does anyone know what's happening??
Check you have spring-tx dependencies (or any other spring dependency) in your class path for it to use your schema. All schemas referenced should map to a spring dependency.
xmlns:tx="http://www.springframework.org/schema/tx"
Check this:
http://www.dashaun.com/2010/03/10/springframework-applicationcontext-woes-unable-to-locate-spring-namespacehandler/
Found workaround:
When running GWT devmode, there is an issue starting the spring appcontext,
the tx...xsd cannot be found. This is related to the classloader defined
in this Devmode class of GWT, which delegates to the systemclassloader
(override of jetty)
see: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/ac495ee6605d21b4
This occurs only when defining the tag in spring which is needed for
processing #Transactional annotations for transactions.
The only way to solve it I found (after 2 days) is to look in the stacktrace and find which class of Spring
invoked xerces (since it is xerces which can't find the file). This was "DefaultDocumentLoader"
This class is in spring-beans.jar.
=> So what I did is, I copied all classes from spring-tx.jar into the new spring-beans.jar
so those classes will be loaded by the same classloader
Then I also merged the META-INF/spring.handlers, spring.schemas, spring.tooling files,
All is now in a new jar i've created: spring-beans-tx-3.0.5.RELEASE.jar
This new jar is the first in the classpath of my project.
In this case it works !!