报错:
12:50:52.361 [http-nio-8080-exec-6] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sign' defined in file [D:\Bin\Net\apache-tomcat-9.0.41\webapps\Aplp\WEB-INF\classes\xyz\zixiu\aplp\Controller\Sign.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [xyz.zixiu.aplp.Controller.Sign]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryUser' defined in class path resource [ApplicationContext/ac-SqlSessionsFactoryUser.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [Mapper/User/StudentMapper.xml]'; nested exception is java.io.FileNotFoundException: class path resource [Mapper/User/StudentMapper.xml] cannot be opened because it does not exist
找不到 Mapper/User/StudentMapper.xml
但我的项目目录里面是有的
而我到打包后的目录apache-tomcat-9.0.41\webapps\Aplp\WEB-INF\classes里面去找的时候发现,他是有的,但名字是小写,是这个目录以前的文件名,这可能是因为IDEA的重构的执行问题
PS C:\Users\zixiu> cd D:\Bin\Net\apache-tomcat-9.0.41\webapps\Aplp\WEB-INF\classes
PS D:\Bin\Net\apache-tomcat-9.0.41\webapps\Aplp\WEB-INF\classes> ls
目录: D:\Bin\Net\apache-tomcat-9.0.41\webapps\Aplp\WEB-INF\classes
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2021/4/23 12:50 ApplicationContext
d----- 2021/4/23 12:50 DB
d----- 2021/4/23 12:50 mapper
d----- 2021/4/23 12:50 Properties
d----- 2021/4/23 12:50 User
d----- 2021/4/23 12:50 xyz
-a---- 2021/4/23 12:32 733 applicationContext-DB.xml
-a---- 2021/4/23 12:32 735 applicationContext-User.xml
-a---- 2021/4/22 13:16 3738 log4j.properties
-a---- 2021/4/23 12:32 1330 spring-mvc.xml
解决方案就是将 .idea/workspace.xml里面出现所有的原文件名都改成现文件名
(这些配置也可能在idea/artifacts下面的两个xml文件里)
例如我把
<change beforePath="$PROJECT_DIR$/config/mapper/DB/DBMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/DB/DBMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/mapper/User/AdminMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/User/AdminMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/mapper/User/StudentMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/User/StudentMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/mapper/User/TeacherMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/User/TeacherMapper.xml" afterDir="false" />
改成了
<change beforePath="$PROJECT_DIR$/config/Mapper/DB/DBMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/DB/DBMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/Mapper/User/AdminMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/User/AdminMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/Mapper/User/StudentMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/User/StudentMapper.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/Mapper/User/TeacherMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/config/Mapper/User/TeacherMapper.xml" afterDir="false" />
用替换毕竟方便,不会漏,但一定要把关键词尽量填完整,不然容易误伤别的句子