连续获取java.lang.NoClassDefFoundError:org / springframework / beans / FatalBeanException

时间:2015-03-02 15:23:52

标签: java spring

我已经阅读了许多与此错误相关的帖子,并且不明白为什么我连续收到此错误,即使我在相同版本的类路径中都有所有jar。

我在没有Maven的情况下使用Spring 3.2.9,Hibernate,Tomcat,Java7和Eclipse Juno。

我还在学习Spring MVC并且不太清楚这个错误是如何解决的。

    package com.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.anil.bean.Student;
import com.test.service.StudentService;


@Controller
public class StudentController {

@Autowired
private StudentService studentservice;
public void setStudentservice(StudentService studentservice) {
    this.studentservice = studentservice;
}

@RequestMapping(value = "/", method = RequestMethod.GET)
public String listStudent(ModelMap map){
    map.addAttribute("student", new Student());
    map.addAttribute("studentList", studentservice.getstudentlist());
    return "index";
}

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addStudent(@ModelAttribute(value="student") Student student, BindingResult result){
studentservice.addstudent(student);
return "redirect:/";
}
@RequestMapping(value = "/delete/{age}")
public String deleteStudent(@PathVariable("age") Integer age){
    studentservice.deletestudent(age);
    return "redirect:/";
}
}

DAO实施

    package com.test.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.anil.bean.Student;

@Repository
public class StudentDAOimpl implements StudentDAO{

    private SessionFactory sessionFactory;
    @Override
    public void addstudent(Student student) {
        this.sessionFactory.getCurrentSession().save(student);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Student> getstudentlist() {
        return this.sessionFactory.getCurrentSession().createQuery("from Student").list();
    }

    @Override
    public void deletestudent(Integer age) {
        Student student = (Student) sessionFactory.getCurrentSession().load(Student.class, age);
        if(null != student)
        this.sessionFactory.getCurrentSession().delete(student);
    }

}

服务类

    package com.test.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.anil.bean.Student;
import com.test.dao.StudentDAO;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDAO studentdao;

    @Override
    @Transactional
    public void addstudent(Student student) {
        studentdao.addstudent(student);
    }

    public void setStudentdao(StudentDAO studentdao) {
        this.studentdao = studentdao;
    }

    @Override
    @Transactional
    public List<Student> getstudentlist() {
        return studentdao.getstudentlist();
    }

    @Override
    @Transactional
    public void deletestudent(Integer age) {
        studentdao.deletestudent(age);
    }

}

的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"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

<display-name>Archetype Created Web Application</display-name>
    <welcome-file-list>
        <welcome-file>/WEB-INF/some.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>employee</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>employee</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/employee-servlet.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>    
</web-app>

的应用上下文

    <?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:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    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
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    <context:annotation-config />
    <context:component-scan base-package="com.test.controller" />

    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"  value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="prefix" value="/WEB-INF/view/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="prefix" value="/WEB-INF/resourses/"></property>
        <property name="suffix" value=".prop*"></property>
        <property name="defaultEncoding" value="UTF-8"></property>
    </bean>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties"> </bean>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
        p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
        p:password="${jdbc.password}"></bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="configLocation" value="/WEB-INF/resourses/hibernate.cfg.xml"></property>
            <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
            </property>

            <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>
      <bean id="StudentDAO" class="com.test.dao.StudentDAOimpl" lazy-init="true"></bean>
    <bean id="StudentService" class="com.test.service.StudentServiceImpl" lazy-init="true"></bean>   
    <tx:annotation-driven />
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    </beans>

异常

    Mar 02, 2015 8:37:32 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_67\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk1.7.0_67/bin/../jre/bin/client;C:/Program Files/Java/jdk1.7.0_67/bin/../jre/bin;C:/Program Files/Java/jdk1.7.0_67/bin/../jre/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_67\bin;C:\apache-tomcat-7.0.52;\bin;C:\Program Files\Maven\apache-maven-3.2.5\bin;C:\HashiCorp\Vagrant\bin;c:\Users\Rajesh\AppData\Local\atom\bin;C:\Users\Rajesh\AppData\Local\atom\bin;C:\Users\Rajesh\Desktop\eclipse;;.
Mar 02, 2015 8:37:33 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Springtest' did not find a matching property.
Mar 02, 2015 8:37:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 02, 2015 8:37:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 02, 2015 8:37:33 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 749 ms
Mar 02, 2015 8:37:33 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 02, 2015 8:37:33 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.55
Mar 02, 2015 8:37:34 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [140] milliseconds.
Mar 02, 2015 8:37:34 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:530)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:512)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4907)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Mar 02, 2015 8:37:34 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Mar 02, 2015 8:37:34 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Mar 02, 2015 8:37:34 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/Springtest] startup failed due to previous errors
Mar 02, 2015 8:37:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 02, 2015 8:37:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 02, 2015 8:37:34 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1346 ms

我路径中的罐子

enter image description here

可以帮助解决这些问题。 提前谢谢。

1 个答案:

答案 0 :(得分:-1)

你的课程路径中没有它,请仔细检查,我相信你会发现错误。