1、tomcat application context配置的问题 一定要把Application context改成 /
2、web.xml配置监听器类对应的完全限定名是错误的 ContextLoaderListener是监听器加载 其作用是指定在Web应用程序启动时载入Ioc容器,并且在web容器启动的时候,容器会调用contextInitialized() 方法,来初始化spring的IOC容器,关闭的时候调用contextDestroyed()销毁容器 ContextCleanupListener 是清除监听器
✔:< listener- class > org. springframework. web. context. ContextLoaderListener< / listener- class >
×:< listener- class > org. springframework. web. context. ContextCleanupListener< / listener- class >
3、扫描spring配置文件通配符设置问题 classpath:resource/springconfig/applicationContex(t)-*.xml 这里是漏写了一个 t 导致 对应的spring配置文件不能加载
4、页面静态资源不生效(css/js/png/jpg等) 可能是web.xml或者springmvc-servlet.xml没有进行静态资源的配置 可能是浏览器缓存导致的,如果是chrome浏览器,清空缓存的快捷键是ctrl + shift + delete,清空缓存
5、lib文件夹的位置 如果是java基础项目,那么lib文件夹和src平级即可。 如果是java enterprise项目,那么lib文件夹 应该在 web -> WEB-INF下
6、springmvc配置文件的头和地址不一致 ×:xmlns:mvc=“http://www.springframework.org/schema/cache” √:xmlns:mvc=“http://www.springframework.org/schema/mvc”
7、springmvc视图配置错误 视图解析器配置错误导致404,不需要id属性
< ! -- 视图解析器 -- >
< bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" ~ ~ id= "internalResourceViewResolver" ~ ~ >
< ! -- 设置属性 -- >
< property name= "prefix" value= "/WEB-INF/jsp" / >
< property name= "suffix" value= ".jsp" / >
< / bean>
页面效果:HTTP Status 404 - / WEB- INF/ jsplogin. jsp
8、文件上传的问题 文件上传的id不能乱写 , jsp页面中的表单要增加<form action="#" method="post"enctype=“multipart/form-data”> Controller类 上面要增加 @MultipartConfig 注解
< bean id= "multipartResolver" class = "org.springframework.web.multipart.commons.CommonsMultipartResolver" >
< property name= "defaultEncoding" value= "utf-8" / >
< / bean>
9、mybatis映射器接口扫描 一定要扫到mapper层
org. apache. ibatis. binding. BindingException: Invalid bound statement ( not found) : com. colin. service. UserService. selectUserByUser
< ! -- 配置Mapper层java类扫描 -- >
< bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer" >
< ! -- 设置Mapper扫描包 -- >
< property name= "basePackage" value= "com.colin" / > 注意问题在这里,要扫描到mapper文件夹那一层
< property name= "sqlSessionFactoryBeanName" value= "sqlSessionFactory" / >
< / bean>
10、设置扫描mapper.xml文件 *Mapper.xml的作用是配合着命名规范来对文件的扫描起到了一个限制作用,如果不尾部不是Mapper结尾的xml文件是无法生效的
< property name= "mapperLocations" value= "classpath:resource/mapperxmlconfig/*Mapper.xml" / >
错误实例:mybatis子配置文件命名为 StudentMapper.xml.xml
11、log4j.properties配置文件要写在src的根目录下 log4j.jar查找文件的时候是先去代码根目录下去找log4j.properties,src运行后的发布目录就是代码根目录 ,如果不习惯或者有别的要求可以直接修改log4j的源代码 使用你自己的加载配置文件的路径即可
12、mybatis主配置文件中子标签的顺序问题 The content of element type “configuration” must match “(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)”.
13、jdbc的密码错误 java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
14、拼写错误 ① 查询的时候字段名不对,表单中的name属性的值和类中的属性名不一致② update 表名 set 字段名 = 值 and 字段名 = 值,这里不应该是and 而应该是逗号③ select 字段 from 表名 where 字段名 = 值 ,字段名 = 值 ,这里不应该是逗号 而应该是and 这里不应该是逗号 而应该是and
15、mybatis进行关联查询 如果进行mybatis进行关联查询,并且结果集用resultMap来接收,那么一定要记住在select标签中将resultType属性改为自定义的resultMap