Spring root WebApplicationContext会启动两次

本文记录了一位开发者在使用springspringmvchibernate框架进行项目开发时遇到的SpringrootWebApplicationContext启动两次的问题。通过调整项目的WebProjectSettings的Contextroot设置,成功解决了这一困扰,避免了不必要的资源消耗。

最近遇到一个很奇怪的问题在这里记录一下

spring springmvc hibernate 项目

在 eclipse 下开发。
Spring root WebApplicationContext会启动两次

Initializing Spring root WebApplicationContext
......
Initializing Spring FrameworkServlet 'dispatcherServlet'
......



Initializing Spring root WebApplicationContext
......
Initializing Spring FrameworkServlet 'dispatcherServlet'
......

一直以为是配置文件的问题,在spring和springmvc 扫描包的时候出的问题,但是改了好几天 一直没有效果,

但是 原本的项目 名后来被改过,不过没注意过什么时候开始,变成启动两次了,
但是
项目的Web Project Settings 的Context root 是原先的项目名,改成后面的项目后,就不会启动两次了,不知道是什么原因,在这里记录一下。

代码报错六月 10, 2025 9:51:26 上午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-bio-8080"] 六月 10, 2025 9:51:26 上午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Tomcat 六月 10, 2025 9:51:26 上午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.47 六月 10, 2025 9:51:28 上午 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 六月 10, 2025 9:51:28 上午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. 六月 10, 2025 9:51:31 上午 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookService': Unsatisfied dependency expressed through field 'bookMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookMapper' defined in file [D:\ideaworkspace\BookManagementSystem2\target\classes\com\example\book\dao\BookMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\ideaworkspace\BookManagementSystem2\target\classes\mapper\BookMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.example.book.dao.
最新发布
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值