dccordell dccordell - 6 months ago 95
Java Question

Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/io/Resource - using spring-core.4_2_5

I'm trying to deploy my REST service using Tomcat 6 and getting the above mentioned error while trying to start tomcat. This app runs fine in Jetty.

All research has pointed to a missing spring-core jar file in my WAR file, but it is already there as far as I can tell.

Any ideas what could be missing/no configured correctly? We are using Java 7.

Here is a bit more of my console output. Please let me know if I can provide any other info to help figure out the problem.

15:52:31.713 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'cxf.config0'
15:52:31.713 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'loggingInInterceptor'
15:52:31.713 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'loggingOutInterceptor'
15:52:31.713 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean 'dynamicPropertyUtil'
15:52:31.713 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'dynamicPropertyUtil'
15:52:31.714 [main] WARN o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicPropertyUtil' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
15:52:31.714 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@360c65bd: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,productQualificationSOAP,cxf.config0,abstractLoggingInterceptor,loggingInInterceptor,loggingOutInterceptor,dynamicPropertyUtil,cgsProductQualificationGatewayHandler,filterLoopQualForEOSRulesHandler,productSpecsToGenericServiceTypeMapper,template,consumerTemplate,cgsProductQualificationSvcsCamelContext:beanPostProcessor,cgsProductQualificationSvcsCamelContext]; root of factory hierarchy
15:52:31.714 [main] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy method 'shutdown' on bean with name 'cxf'
15:52:31.748 [main] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicPropertyUtil' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]


and a bit lower in the same exception...

... 28 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.Resource
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_25]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_25]


The WEB-INF\lib of my WAR file...

Dependency hierarchy in my POM.xml

UPDATE: Here is my applicationContext.xml and pom.xml. I removed as much of the seemingly irrelevant code as I thought possible to make it not so huge..

applicationContext.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:cxf="http://camel.apache.org/schema/cxf"
xmlns:cxfbus="http://cxf.apache.org/core"
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
http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<!-- <import resource="classpath:META-INF/spring/cxfClientContext.xml" /> -->


<cxf:cxfEndpoint id="productQualificationSOAP" address="/ProductQualification"
endpointName="s:ProductQualificationSoap" serviceName="s:ProductQualification"
serviceClass="com.mycompany.cgs.marketingoffermanagement.productqualification.ProductQualificationSoapImpl"
wsdlURL="META-INF/wsdl/productQualification/ProductQualification.wsdl"
xmlns:s="http://cgs.mycompany.com/MarketingOfferManagement/ProductQualification">
</cxf:cxfEndpoint>
<cxfbus:bus>
<cxfbus:inInterceptors>
<ref bean="loggingInInterceptor" />
</cxfbus:inInterceptors>
<cxfbus:outInterceptors>
<ref bean="loggingOutInterceptor" />
</cxfbus:outInterceptors>
<cxfbus:outFaultInterceptors>
<ref bean="loggingOutInterceptor" />
</cxfbus:outFaultInterceptors>
<cxfbus:inFaultInterceptors>
<ref bean="loggingInInterceptor" />
</cxfbus:inFaultInterceptors>
</cxfbus:bus>

<bean id="abstractLoggingInterceptor" abstract="true">
<property name="prettyLogging" value="true" />
</bean>
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"
parent="abstractLoggingInterceptor" />
<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"
parent="abstractLoggingInterceptor" />

<bean id="dynamicPropertyUtil"
class="com.myco.cgs.productorder.services.productQualification.util.DynamicPropertyUtil" />

<bean id="cgsProductQualificationGatewayHandler"
class="com.myco.cgs.productorder.services.productQualification.CGSProductQualificationGatewayHandler" />
<bean id="filterLoopQualForEOSRulesHandler"
class="com.myco.cgs.productorder.services.filterLoopQual.FilterLoopQualForEOSRulesHandler" />
<bean id="productSpecsToGenericServiceTypeMapper"
class="com.myco.cgs.services.dataaccess.productspec.mapper.ProductSpecToUnderlyingMapper" />

<camelContext id="cgsProductQualificationSvcsCamelContext"
xmlns="http://camel.apache.org/schema/spring">
<packageScan>
<package>com.myco.cgs.productorder.services.productQualification.camel.route</package>
</packageScan>
</camelContext>

</beans>


pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx.xxx.xx.xxx</groupId>
<artifactId>productQualification</artifactId>
<name>Project Name</name>
<version>1.0</version>
<description>My Web Service</description>
<url>http://www.url.com</url>
<packaging>war</packaging>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.0.6.RELEASE</spring.version>
<camel.version>2.17.1</camel.version>
<cxf.version>3.1.6</cxf.version>
<junit.version>4.10</junit.version>
<slf4j.version>1.6.6</slf4j.version>
<api-java.MiddlewareUtils.version>15.1.0.1</api-java.MiddlewareUtils.version>
<api-java.ensemble-api.version>16.1.0.1</api-java.ensemble-api.version>
<!-- <api-java.MiddlewareUtils.version>15.1.0.1</api-java.MiddlewareUtils.version> -->
</properties>

...

<dependencies>
<!-- Jolt -->
<dependency>
<groupId>jolt</groupId>
<artifactId>jolt</artifactId>
<version>1.0</version>
<!--<scope>system</scope> <systemPath>${basedir}/lib/build/jolt.jar</systemPath> -->
</dependency>
<dependency>
<groupId>joltjse</groupId>
<artifactId>joltjse</artifactId>
<version>1.0</version>
<!--<scope>system</scope> <systemPath>${basedir}/lib/build/joltjse.jar</systemPath> -->
</dependency>
<dependency>
<groupId>joltwls</groupId>
<artifactId>joltwls</artifactId>
<version>1.0</version>
<!--<scope>system</scope> <systemPath>${basedir}/lib/build/joltwls.jar</systemPath> -->
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.0.9</version>
<exclusions>
<exclusion>
<artifactId>javax.servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Camel Dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${camel.version}</version>
<exclusions>
<exclusion>
<artifactId>javax.servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel.version}</version>
<exclusions>
<exclusion>
<artifactId>javax.servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description</artifactId>
<version>${cxf.version}</version>
</dependency>

<!-- Spring Web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.1</version>
</dependency>

<!-- Axis -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
<exclusions>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
<exclusion>
<artifactId>mail</artifactId>
<groupId>javax.mail</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0ctl</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.4</version>
<!-- <scope>provided</scope> -->
</dependency>

<!-- RPC -->
<dependency>
<groupId>javax.xml</groupId>
<!-- <groupId>javax.xml.rpc</groupId> -->
<artifactId>jaxrpc</artifactId>
<version>1.1</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<!-- Commons Dependencies -->
<dependency>
<groupId>api-java</groupId>
<artifactId>MiddlewareUtils</artifactId>
<version>${api-java.MiddlewareUtils.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>api-java</groupId>
<artifactId>ensemble-api</artifactId>
<version>${api-java.ensemble-api.version}</version>
<exclusions>
<exclusion>
<groupId>neethi</groupId>
<artifactId>neethi</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.mycompany.cgs</groupId>
<artifactId>dataAccess</artifactId>
<version>2.1</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>joltjse</groupId>
<artifactId>joltjse</artifactId>
<version>1.0</version>
<!--<scope>system</scope> <systemPath>${basedir}/lib/build/joltjse.jar</systemPath> -->
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>orai18n</groupId>
<artifactId>orai18n</artifactId>
<version>11.1.0.7.0</version>
</dependency>

<!-- Apache Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>

<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>2.15.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.4.0</version>
</dependency>


</dependencies>

...

<build>
<defaultGoal>install</defaultGoal>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>underlyingServices/src/main/resources</directory>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>

<execution>
<id>Product Qualification Service WSDL2JAVA</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/META-INF/wsdl/productQualification/ProductQualification.wsdl</wsdl>
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-autoNameResolution</extraarg>
<extraarg>-xjc-Xannotate</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>src/main/resources/META-INF/xsd/bindings/GlobalProductQualificationBindings.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>

<!-- plugin so you can run mvn jetty:run -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<configuration>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<systemProperties>
<systemProperty>
<name>com.sun.management.jmxremote</name>
<value />
</systemProperty>
</systemProperties>
<stopPort>8091</stopPort>
<stopKey>stopItYou</stopKey>
<contextPath>/</contextPath>
<jvmArgs>-Xms128M -Xmx512M -XX:PermSize=16M -XX:MaxPermSize=128M</jvmArgs>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>

Answer

Well, the issue is resolved, although I'm not quite sure how. I added the spring-core dependency to my pom directly, instead of pulling it in though camel-spring. I also used version 4.2.6 instead of 4.2.5. Once I did this, the issue was resolved and tomcat started just fine. Wew!

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.6.RELEASE</version>
</dependency>