Topic: 请帮忙看看这个简单的spring程序是什么问题? |
Print this page |
1.请帮忙看看这个简单的spring程序是什么问题? | Copy to clipboard |
Posted by: benbon Posted on: 2006-03-17 14:57 错误如下: exception javax.servlet.ServletException: Error instantiating servlet class net.testSpring.servlet.MainServlet org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) java.lang.Thread.run(Thread.java:595) root cause java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractApplicationContext java.lang.Class.getDeclaredConstructors0(Native Method) java.lang.Class.privateGetDeclaredConstructors(Class.java:2328) java.lang.Class.getConstructor0(Class.java:2640) java.lang.Class.newInstance0(Class.java:321) java.lang.Class.newInstance(Class.java:303) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) java.lang.Thread.run(Thread.java:595) note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs. 程序: package net.testSpring.sys; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class AppContext { private static AppContext instance; private AbstractApplicationContext appContext; public synchronized static AppContext getInstance() { if (instance == null) { instance = new AppContext(); } return instance; } private AppContext() { try{ this.appContext = new ClassPathXmlApplicationContext( "/applicationContext.xml"); }catch(Exception e){ System.out.println(e.getMessage()); } if(appContext!=null) System.out.println("get AppContext success!"); } public AbstractApplicationContext getAppContext() { return appContext; } } ----------------------------------------------------------------------------------------- package net.testSpring.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.testSpring.beans.TestBean; import net.testSpring.sys.AppContext; import org.springframework.context.ApplicationContext; public class MainServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to * post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=gb2312"); try { ApplicationContext ac = AppContext.getInstance().getAppContext(); TestBean tb = (TestBean) ac.getBean("test"); String vs_text = tb.getContent(); System.out.println(vs_text); } catch (Exception e) { e.printStackTrace(); } System.out.println("hello"); } } ---------------------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="test" class="net.testSpring.beans.TestBean"> <property name="vs_test"><value>Hello World</value></property> </bean> </beans> ------------------------------------------------------------ applicationContext.xml放在web-inf/classes下面 |
2.Re:请帮忙看看这个简单的spring程序是什么问题? [Re: benbon] | Copy to clipboard |
Posted by: zcjl Posted on: 2006-03-17 16:00 java.lang.NoClassDefFoundError: org/springframework/context/support/AbstractApplicationContext classpath中不存在这个类 建议把spring.jar或者spring-context.jar加入到classpath中 |
3.Re:请帮忙看看这个简单的spring程序是什么问题? [Re: benbon] | Copy to clipboard |
Posted by: benbon Posted on: 2006-03-17 16:51 不可能吧,我是用myeclipse做的,所有的包都导入了 |
4.Re:请帮忙看看这个简单的spring程序是什么问题? [Re: benbon] | Copy to clipboard |
Posted by: floater Posted on: 2006-03-17 22:52 benbon wrote: why not possible? In this world, anything is possible, . That's what the msg says. There are many possible reasons, missing jar files, corrupted jar files, classloader issues, wrong version of jars, to name a few. |
5.Re:请帮忙看看这个简单的spring程序是什么问题? [Re: floater] | Copy to clipboard |
Posted by: bluepure Posted on: 2006-03-18 18:48 myeclipse的包导入有两种方式,一种是类似环境变量,一种是把所有jar复制到webapp的lib文件夹下面。 你选择的是第一种方式,因此在web方式下运行就找不到库文件了。 看我的抓图,要选择下面那个copy: |
6.Re:请帮忙看看这个简单的spring程序是什么问题? [Re: benbon] | Copy to clipboard |
Posted by: rockykid Posted on: 2006-05-21 15:23 那顺便问一下楼上大虾,第一种方式如何用 ?谢谢! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |