结合Maven的Eclipse web工程部署到Tomcat时报错! 但Jetty正常运行, 是Eclipse的jar包冲突吗? 大神求解!

时间:2021-03-20 15:58:55
使用Maven的依赖管理导入jar包, 使用Eclipse将web工程部署到Tomcat时报错, 页面打不开显示404错误!  结合Maven的Eclipse web工程部署到Tomcat时报错! 但Jetty正常运行, 是Eclipse的jar包冲突吗? 大神求解!  结合Maven的Eclipse web工程部署到Tomcat时报错! 但Jetty正常运行, 是Eclipse的jar包冲突吗? 大神求解!

但奇怪的是Jetty可以正常运行, 是Eclipse的jar包冲突吗? 连续弄了好几天都无解, 求大神帮忙! 结合Maven的Eclipse web工程部署到Tomcat时报错! 但Jetty正常运行, 是Eclipse的jar包冲突吗? 大神求解!

========控制台报错=========


严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [main.java.com.jianzhi.mvcdemo.dao.BookinfoDao] for bean with name 'bdao' defined in ServletContext resource [/WEB-INF/configs/spring/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: main.java.com.jianzhi.mvcdemo.dao.BookinfoDao
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1386)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:957)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: main.java.com.jianzhi.mvcdemo.dao.BookinfoDao
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1309)
... 19 more



下面是我的POM依赖文档:

============pom.xml============

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>helloworld</groupId>
  <artifactId>spring-mvc-study</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>spring-mvc-study Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
   <commons-lang.version>2.6</commons-lang.version>
   <slf4j.version>1.7.6</slf4j.version>
   <spring.version>4.1.3.RELEASE</spring.version>
  </properties>
  
  <dependencyManagement>
   <dependencies>
   <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-framework-bom</artifactId>
   <!-- <version>${spring.version}</version> -->
   <version>${spring.version}</version>
   <type>pom</type>
   <scope>import</scope>
   </dependency>
   </dependencies>
  </dependencyManagement>
  
  <dependencies>
   <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   </dependency>
  
   <dependency>
   <groupId>commons-lang</groupId>
   <artifactId>commons-lang</artifactId>
   <version>${commons-lang.version}</version>
   </dependency>

   <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>${slf4j.version}</version>
   <exclusions>
   <exclusion>
   <artifactId>slf4j-api</artifactId>
   <groupId>org.slf4j</groupId>
   </exclusion>
   </exclusions>
   </dependency>
  
<!--    <dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5-pre8</version>
</dependency> -->

<dependency>  
        <groupId>org.springframework</groupId>  
        <artifactId>spring-jdbc</artifactId>  
        <version>${spring.version}</version>  
    </dependency>
          
   <dependency> 
  <groupId>jstl</groupId> 
  <artifactId>jstl</artifactId> 
  <version>1.2</version> 
</dependency> 

<dependency> 
  <groupId>taglibs</groupId> 
  <artifactId>standard</artifactId> 
  <version>1.1.2</version> 
</dependency>

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.0.5</version>
</dependency>

<dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
</dependency>
  </dependencies>
  <build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.2.8.v20150217</version>
    </plugin>
  </plugins>
</build>
</project>





=========applicationContext.xml==========


<?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:p="http://www.springframework.org/schema/p" 
       xmlns:context="http://www.springframework.org/schema/context"  
       xmlns:mvc="http://www.springframework.org/schema/mvc" 
       
       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/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--配置数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/ebook?useunicode=true&amp;characterEncoding=utf8"/>
        <property name="username" value="root"/>
        <property name="password" value="1234"/>
    </bean>
    
    <bean id="ASBaseDao" class="main.java.com.jianzhi.mvcdemo.dao.ASBaseDao" abstract="true">
     <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="bdao" class="main.java.com.jianzhi.mvcdemo.dao.BookinfoDao" parent="ASBaseDao"/>
    
    <bean id="bizImpl" class="main.java.com.jianzhi.mvcdemo.service.BizImpl">
        <property name="bdao" ref="bdao"></property>  
    </bean>
    
</beans>

4 个解决方案

#1


坐等答复,送分!

#2


maven导jar包不是它自己去仓库下吗?是不是没下载好!你直接把现在jar包拷过去不行吗。
还可能要点一下maven install

#3


引用 2楼MONKEY_D_GARP 的回复:
maven导jar包不是它自己去仓库下吗?是不是没下载好!你直接把现在jar包拷过去不行吗。
还可能要点一下maven install
只要在eclipse中配置了pom.xml就会自动下载,我用的是阿里云的maven中心,包应该都下好了,只是这个pom.xml是不是没写对?为什么jetty运行成功而tomcat不行?

#4


该回复于2018-01-31 16:24:07被管理员删除

#1


坐等答复,送分!

#2


maven导jar包不是它自己去仓库下吗?是不是没下载好!你直接把现在jar包拷过去不行吗。
还可能要点一下maven install

#3


引用 2楼MONKEY_D_GARP 的回复:
maven导jar包不是它自己去仓库下吗?是不是没下载好!你直接把现在jar包拷过去不行吗。
还可能要点一下maven install
只要在eclipse中配置了pom.xml就会自动下载,我用的是阿里云的maven中心,包应该都下好了,只是这个pom.xml是不是没写对?为什么jetty运行成功而tomcat不行?

#4


该回复于2018-01-31 16:24:07被管理员删除