SSM项目启动tomcat抛出ClassNotFoundException

项目采用ssm框架,我为了让项目的jar包可以让其他project也可以使用,将项目需要的jar包放进一个Faceted Project中,这是模仿之前实习公司的作法,然后配置web.xml、applicationContext.xml等,各项完事,在BuildPath正常,但是在启动tomcat时反复提示

java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

我就很纳闷,然后突然想起来之前遇到类似的问题,是通过修改项目的.classpath文件解决,我于是打开了该文件,果然看到原本正确的设置是这样:

......
    <classpathentry kind="lib" path="/Lib/castor-1.0.1-xml.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="/Lib/commons-beanutils.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="/Lib/commons-collections-3.2.1.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="/Lib/commons-dbcp-1.4.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="/Lib/commons-digester.jar">
......

但我的是这样的

......
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    <classpathentry kind="lib" path="/Lib/antlr-2.7.6.jar"/>
    <classpathentry kind="lib" path="/Lib/aopalliance-1.0.jar"/>
    <classpathentry kind="lib" path="/Lib/cglib-2.2.jar"/>
    <classpathentry kind="lib" path="/Lib/com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar"/>
    <classpathentry kind="lib" path="/Lib/commons-collections-3.1.jar"/>
    <classpathentry kind="lib" path="/Lib/commons-fileupload-1.2.1.jar"/>
    <classpathentry kind="lib" path="/Lib/commons-io-1.3.2.jar"/>
    <classpathentry kind="lib" path="/Lib/commons-lang.jar"/>
    <classpathentry kind="lib" path="/Lib/commons-logging-1.1.1.jar"/>
    <classpathentry kind="lib" path="/Lib/dom4j-1.6.1.jar"/>
......

也就是如果通过引用外部项目的jar包后需要.classpath文件中设置依赖路径,否则myeclipse就找到这些jar包,就会报出那个错误。

于是将文件中的
/>
替换为
><attributes><attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/></attributes></classpathentry>
问题解决。

这个问题充分说明,每个人问题都不一定是一样的,遇到问题还是需要自己找到问题的根源去解决。只在网上搜是治标不治本的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值