I have read many posts related this error and did not understand why, i am getting this error continuously even i have all jars in class path of same version. I am using spring 3.2.9, Hibernate, Tomcat, Java7 and Eclipse Juno without maven. I am still learning Spring MVC and did not understand quite properly, how this error was knocking at.
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 implementation
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);
}
}
Service class
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://ift.tt/ra1lAU"
xmlns="http://ift.tt/nSRXKP"
xmlns:web="http://ift.tt/LU8AHS"
xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/LU8AHS"
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>
Application-context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7"
xmlns:jee="http://ift.tt/OpNaZ5"
xmlns:lang="http://ift.tt/OGfeTY"
xmlns:p="http://ift.tt/1jdM0fE"
xmlns:tx="http://ift.tt/OGfeU2"
xmlns:util="http://ift.tt/OGfeTW"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG
http://ift.tt/GArMu7 http://ift.tt/1jdLYo7
http://ift.tt/OpNaZ5 http://ift.tt/1feTnjL
http://ift.tt/OGfeTY http://ift.tt/1feTlrY
http://ift.tt/OGfeU2 http://ift.tt/18tm2Tg
http://ift.tt/OGfeTW http://ift.tt/1feTls0">
<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>
Exception
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
Jars in my path
Can any help out of these problem. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire