我有一个动态的web项目,我没有使用Maven(所以,我没有pom.xml)。我的控制器适用于我为测试目的而创建的HelloWorldController。我收到了以下错误,我认为这与服务或JpaDao课程相关。我还将添加这些文件。如果您还有其他需要,我还可以添加和更新我的帖子。提前谢谢。
我有这样的错误日志:
SEVERE: Servlet.service() for servlet [spring] in context with path [/Spring3MVC] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: antlr/RecognitionException] with root cause
java.lang.ClassNotFoundException: antlr.RecognitionException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:59)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:103)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:221)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:199)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1778)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
at com.sun.proxy.$Proxy32.createQuery(Unknown Source)
at com.spitter.web.dao.JpaSpitterDao.getRecentSpittle(JpaSpitterDao.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy34.getRecentSpittle(Unknown Source)
at com.spitter.web.service.SpitterServiceImpl.getRecentSpittles(SpitterServiceImpl.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy35.getRecentSpittles(Unknown Source)
at com.spitter.web.controller.HomeController.showHomePage(HomeController.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
JpaSpitterDao.java:
package com.spitter.web.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.spitter.web.domain.Spitter;
import com.spitter.web.domain.Spittle;
@Repository("spitterDao")
@Transactional
public class JpaSpitterDao implements SpitterDao {
private static final String RECENT_SPITTLES =
"SELECT s FROM Spittle s";
private static final String ALL_SPITTERS =
"SELECT s FROM Spitter s";
private static final String SPITTER_FOR_USERNAME =
"SELECT s FROM Spitter s WHERE s.username = :username";
private static final String SPITTLES_BY_USERNAME =
"SELECT s FROM Spittle s WHERE s.spitter.username = :username";
@PersistenceContext
private EntityManager em; //<co id="co_injectEM"/>
public void addSpitter(Spitter spitter) {
em.persist(spitter); //<co id="co_useEM"/>
}
public Spitter getSpitterById(long id) {
return em.find(Spitter.class, id); //<co id="co_useEM"/>
}
public void saveSpitter(Spitter spitter) {
em.merge(spitter); //<co id="co_useEM"/>
}
//<end id="java_contextualJpaDao"/>
@SuppressWarnings("unchecked")
public List<Spittle> getRecentSpittle() {
return (List<Spittle>) em.createQuery(RECENT_SPITTLES).
getResultList();
}
public void saveSpittle(Spittle spittle) {
em.persist(spittle);
}
@SuppressWarnings("unchecked")
public List<Spittle> getSpittlesForSpitter(
Spitter spitter) {
return (List<Spittle>) em.createQuery(SPITTLES_BY_USERNAME).
setParameter("username", spitter.getUsername()).
getResultList();
}
public Spitter getSpitterByUsername(String username) {
return (Spitter) em.createQuery(SPITTER_FOR_USERNAME).
setParameter("username", username).
getSingleResult();
}
public void deleteSpittle(long id) {
try {
em.remove(getSpittleById(id));
} catch(DataAccessException e) {}
}
public Spittle getSpittleById(long id) {
return em.find(Spittle.class, id);
}
@SuppressWarnings("unchecked")
public List<Spitter> findAllSpitters() {
return em.createQuery(ALL_SPITTERS).getResultList();
}
}
SpitterServiceImpl.java(服务实现):
package com.spitter.web.service;
import static java.lang.Math.min;
import static java.util.Collections.reverse;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.spitter.web.dao.SpitterDao;
import com.spitter.web.domain.Spitter;
import com.spitter.web.domain.Spittle;
@Service("spitterService")
@Transactional(propagation=Propagation.REQUIRED)
public class SpitterServiceImpl implements SpitterService {
public void saveSpittle(Spittle spittle) {
spittle.setWhen(new Date());
spitterDao.saveSpittle(spittle);
}
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public List<Spittle> getRecentSpittles(int count) {
List<Spittle> recentSpittles =
spitterDao.getRecentSpittle();
reverse(recentSpittles);
return recentSpittles.subList(0,
min(49, recentSpittles.size()));
}
public void saveSpitter(Spitter spitter) {
if(spitter.getId() == null) {
spitterDao.addSpitter(spitter);
} else {
spitterDao.saveSpitter(spitter);
}
}
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public Spitter getSpitter(long id) {
return spitterDao.getSpitterById(id);
}
public void startFollowing(Spitter follower, Spitter followee) {
// TODO Auto-generated method stub
}
public List<Spittle> getSpittlesForSpitter(Spitter spitter) {
return spitterDao.getSpittlesForSpitter(spitter);
}
public List<Spittle> getSpittlesForSpitter(String username) {
Spitter spitter = spitterDao.getSpitterByUsername(username);
return getSpittlesForSpitter(spitter);
}
public Spitter getSpitter(String username) {
return spitterDao.getSpitterByUsername(username);
}
public void deleteSpittle(long id) {
spitterDao.deleteSpittle(id);
}
public List<Spitter> getAllSpitters() {
return spitterDao.findAllSpitters();
}
@Autowired
SpitterDao spitterDao;
public Spittle getSpittleById(long id) {
return spitterDao.getSpittleById(id);
}
}
答案 0 :(得分:3)
java.lang.ClassNotFoundException:antlr.RecognitionException显示缺少antlr lib。添加它并完成它:)