配置文件写的时候不细心,找错误的时候流下两行泪…,写配置文件一定要细心细心细心细心细心细心,下面是部分卡了我很久的问题。。
1. java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
这个错误是找不到配置文件了,首先考虑是不是prm.xml中没有加静态资源过滤
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
然后看maven的target中能不能找到配置文件,如果加上还是报错,看一看资源路径是否正确。
==========================================
2. Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.lang.String’ to required type ‘javax.sql.DataSource’ for property ‘dataSource’; nested exception is java.lang.IllegalStateException: Cannot convert value of type ‘java.lang.String’ to required type ‘javax.sql.DataSource’ for property ‘dataSource’: no matching editors or conversion strategy found
'
这个错误让我找了很多天,首先可以肯定是spring整合mybatis的配置文件有问题。
- 首先看创建bean的SqlSessionFactory属性值DataSource赋值是不是ref,不要写成value
- 在mybatis-config.xml和spring-mybatis.xml中不要重复扫描xxxxMapper.xml,重复扫描会出错
- 网上其他方案:配置文件开头加上:default-autowire=“byname”
==========================================
3.配置文件头UTF-8莫名其妙出错
xml配置文件头:这个问题不知道出在哪,偶尔一次运行是正确的,偶尔运行爆红,只要把UTF-8改为UTF8就能正确运行。
==========================================
4.类 ‘xxxServlceImpl’ 为 public,应在文件 ‘xxxServlceImpl.java’ 中声
这是实现类名出错,会导致spring-service.xml配置文件中创建Impl类bean失败。将实现类名改为:BookServiceImpl
==========================================
5.已连接到服务器
[2021-01-23 10:20:06,566] Artifact SSMBuild:war exploded: 正在部署工件,请稍候…
23-Jan-2021 22:20:06.879 涓ラ噸 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 涓�涓垨澶氫釜绛涢�夊櫒鍚姩澶辫触銆傚畬鏁寸殑璇︾粏淇℃伅灏嗗湪鐩稿簲鐨勫鍣ㄦ棩蹇楁枃浠朵腑鎵惧埌
23-Jan-2021 22:20:06.880 涓ラ噸 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 鐢变簬涔嬪墠鐨勯敊璇紝Context[/SSMBuild_war_exploded]鍚姩澶辫触
[2021-01-23 10:20:06,891] Artifact SSMBuild:war exploded: 部署工件时出错。请参阅服务器日志了解详细信息。
23-Jan-2021 22:20:16.347 淇℃伅 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory 鎶妛eb 搴旂敤绋嬪簭閮ㄧ讲鍒扮洰褰� [D:\Tomcat\apache-tomcat-9.0.41\webapps\manager]
23-Jan-2021 22:20:16.390 淇℃伅 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory Web搴旂敤绋嬪簭鐩綍[D:\Tomcat\apache-tomcat-9.0.41\webapps\manager]鐨勯儴缃插凡鍦╗42]姣鍐呭畬鎴�
这个错误是IDEA项目结构中没有添加库文件,很坑,需要自己手动添加,在IDEA中打开项目结构
在WEB-INF中创建一个lib文件夹,然后
把这些库加入lib文件夹应用就可以正常运行了。
暂时就这么多,遇到问题再更新