0

I have mapped each bean properly in my project so as provided the paths accordingly. The project is working fine on the machine it is created. But when other developers import the project and after successful clean & install, tries to run it, it throws exception. In addition, I have viewed some similar titled question but none worked for me.

NOTE: DAO layer or database layer is created as separate project and included into project as a jar.

Exception:

2016-02-26 15:09:33,709 [localhost-startStop-1] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Overriding bean definition for bean 'artistController' with a different definition: replacing [Generic bean: class [com.ceelive.controller.ArtistController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\ceelive-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ceelive\WEB-INF\classes\com\ceelive\controller\ArtistController.class]] with [Generic bean: class [com.ceelive.controller.ArtistController]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in ServletContext resource [/WEB-INF/servlet/ceeliveservlet/servlet-context.xml]]
2016-02-26 15:09:33,921 [localhost-startStop-1] WARN  org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artistController' defined in ServletContext resource [/WEB-INF/servlet/ceeliveservlet/servlet-context.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/ceelive/dao/manager/artist/ArtistDao
2016-02-26 15:09:33,921 [localhost-startStop-1] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artistController' defined in ServletContext resource [/WEB-INF/servlet/ceeliveservlet/servlet-context.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: com/ceelive/dao/manager/artist/ArtistDao
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
 at javax.servlet.GenericServlet.init(GenericServlet.java:158)
 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/ceelive/dao/manager/artist/ArtistDao
 at java.lang.Class.getDeclaredMethods0(Native Method)
 at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
 at java.lang.Class.getDeclaredMethods(Class.java:1975)
 at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
 at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
 at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanF...

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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.cimple</groupId>
  <artifactId>ceelive</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>ceelive Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>

        <!-- Spring Dependencies-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.4.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Need this for json to/from object -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.1.0</version>
        </dependency>

        <!-- jstl Servlet -->
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>

        <!-- Logging -->
        <!-- <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.14</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.3</version>
        </dependency> -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.14</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.14</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.14</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>runtime</scope>
        </dependency>
        <!-- Apache tiles -->
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-api</artifactId>
           <version>2.2.2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-core</artifactId>
           <version>2.2.2</version>
               <!-- <exclusions>
                    <exclusion>
                      <groupId>org.slf4j</groupId>
                      <artifactId>slf4j-jdk14</artifactId>
                    </exclusion>
               </exclusions> -->
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-jsp</artifactId>
           <version>2.2.2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-servlet</artifactId>
           <version>2.2.2</version>
        </dependency>
        <dependency>
           <groupId>org.apache.tiles</groupId>
           <artifactId>tiles-template</artifactId>
           <version>2.2.2</version>
        </dependency>

        <!-- compile only, runtime container will provide this -->
        <!-- Need this for config annotation -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

    <!-- ceeliveDAO - Custom dependency -->
    <dependency>
         <groupId>com.cimple</groupId>
         <artifactId>ceeliveDAO</artifactId>
         <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>ceelive</finalName>

          <pluginManagement>
        <plugins>

            <!-- <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat6-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin> -->
            <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
            </plugin>

            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.3</version>
              <configuration>
                <source>1.8</source>
                <target>1.8</target> 
              </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.11.v20150529</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/spring4ajax</contextPath>
                    </webApp>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    <wtpversion>2.0</wtpversion>
                    <wtpContextName>spring4ajax</wtpContextName>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>


            <plugin>
                <groupId>it.session.maven.plugins</groupId>
                <artifactId>tiles-maven-plugin</artifactId>
                <version>${maventiles.plugin.version}</version>
                <extensions>true</extensions>
            </plugin>
         </plugins>
      </pluginManagement>
  </build>
</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>service</display-name>

    <!-- Deafult pages -->
    <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Log listner -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>ceelive</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet/ceeliveservlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Servlet Mapping -->
   <servlet-mapping>
      <servlet-name>ceelive</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>

servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        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">


   <context:component-scan base-package="com.ceelive.controller" />

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Event Dao Bean -->
    <beans:bean id="eventDao" class="com.ceelive.dao.manager.event.EventDaoImpl">
    </beans:bean>
    <!-- Artist Dao Bean -->
    <beans:bean id="artistDao" class="com.ceelive.dao.manager.artist.ArtistDaoImpl">
    </beans:bean>
    <!-- Event Service Bean -->
    <beans:bean id="eventService" class="com.ceelive.service.event.EventServiceImpl">
        <beans:property name="eventDao" ref="eventDao"></beans:property>
    </beans:bean>
    <!-- Artist Service Bean -->
    <beans:bean id="artistService" class="com.ceelive.service.artist.ArtistServiceImpl">
        <beans:property name="artistDao" ref="artistDao"></beans:property>
    </beans:bean>
    <!-- Event Controller Bean -->
    <beans:bean id="eventController" class="com.ceelive.controller.EventController">
        <beans:property name="eventService" ref="eventService"></beans:property>
        <beans:property name="beanUtil" ref="beanUtil"></beans:property>
    </beans:bean>
    <!-- Artist Controller Bean -->
    <beans:bean id="artistController" class="com.ceelive.controller.ArtistController">
        <beans:property name="artistService" ref="artistService"></beans:property>
        <beans:property name="beanUtil" ref="beanUtil"></beans:property>
    </beans:bean>
    <!-- BeanUtil bean -->
    <beans:bean id="beanUtil" class="com.ceelive.utility.BeanUtil">
    <!-- HibernateConfiguration bean -->
    </beans:bean>
       <beans:bean id="hibernateConfiguration" class="com.ceelive.configuration.HibernateConfiguration">
    </beans:bean>
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
        <beans:bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>/WEB-INF/tiles.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>
    <beans:bean id="tilesViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="viewClass">
            <beans:value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </beans:value>
        </beans:property>
        <beans:property name="order" value="0"/>
    </beans:bean>

    <context:component-scan base-package="com.frameworkonly.tilesapp" />
</beans:beans>
Ali Dehghani
  • 46,221
  • 15
  • 164
  • 151
Ahsan Iqbal
  • 78
  • 1
  • 4
  • 10
  • Could you check, that your `ArtistDao` in package `com.ceelive.dao.manager.artist`? – Solorad Feb 26 '16 at 11:00
  • Your prompt response is highly appreciated. However, yes the file is at the right path. As i have mentioned, the project is working fine on my system; but not on others. – Ahsan Iqbal Feb 26 '16 at 11:03
  • 1
    `DAO layer or database layer is created as separate project and included into project`- it seems the DAO layer jar is present at compile time but not found at runtime. Check the difference between your runtime classpath and others. – Bacteria Feb 26 '16 at 11:04
  • Though your response sounds more valid for now. I am up-to it. And will surly let you know if this is the main reason. But Thanks for the support. – Ahsan Iqbal Feb 26 '16 at 11:42

2 Answers2

1

I think you got the exception because of version conflict.Please check the version of java and tomcat server .

  • I appreciate your reply brother. The project is built on Java 8 & tomcat 7. And as said it is working fine on the machine it is created. But it is not running on other machine. While the same technology is observed there. – Ahsan Iqbal Feb 26 '16 at 11:15
  • Okay ...first you should create war file from your machine and deploy on other machine server . If Application work properly than delete the .m2 file from other developers machine after that clean and install an application . It should be worked. And if you are using eclipse than go to property of project and match project facets. – Akash Panday Feb 26 '16 at 12:22
  • Thanks for the hint Akash. Though it worked when i copied my .m2 in other machine: app runs fine. But i have to find the missing dependencies. – Ahsan Iqbal Feb 26 '16 at 14:26
1

I had resolved same error by adding Tomcat Server into Java Build Path in eclipse.

Right click on the project -> Build Path -> Configure Build Path -> Add library..(appears on the right side of the dialog box) -> Server Runtime -> Select "Apache Tomcat v.." -> Finish

Then run the project on the server.