1. The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files。
原因: 这是由于缺少了一个servlet-api.jar包所引起的。
解决方法:在安装的tomcat下的lib目录里面找到servlet-api.jar包,导入项目下的lib文件夹中即可。
或者:
项目名--> 右键
Property--> 选择
Java Build Path--> 选择
Add External JARs--> 选择
选择servlet-api.jar ,点击确定
2.在web项目中使用HttpServletRequest 的时候,报HttpServletRequest cannot be resolved to a type
同上
3. 在SpringMVC中报400错误,首先要考虑是否是参数绑定异常引起的。
4. SpringMVC上传文件遇到的错误
Request processing failed; nested exception is java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured?
产生原因是,没有配置多媒体解析器multipartResolver
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760000"></property>
<property name="maxInMemorySize" value="40960"></property>
</bean>
5. 在maven项目中,当引入多个xml配置文件的时候,用classpath可能会报错,这时候改为classpath*
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
6. No converter found for return value of type: class java.util.ArrayList
在SpringMVC项目中,如果遇到这个错误,可能是由于项目中没有引入json包导致的
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
如果还是没有解决,在springmvc配置文件中进行如下配置
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
7. 在Spring整合mybatis的时候,报错 Invalid bound statement (not found):
该错误表示某个文件找不到,在idea中运行的时候,会将java文件夹下的java类编译之后与.xml文件一起copy到target目录下,该错误的原因是,有某个文件没有复制过去,这时候,需要在pom.xml中加入如下配置:
<build>
<!--配置资源拷贝插件-->
<resources>
<!--配置main下的文件-->
<resource>
<directory>src/main/java</directory>
<includes>
<!--将main下及其子目录下的.xml文件拷贝-->
<include>**/*.xml</include>
</includes>
</resource>
<!--配置resources下的文件-->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>