• IDEA springboot+myBatis 报错:BindingException: Invalid bound statement (not found)
  • 一般都是dao层的方法会报这种错误,可能是因为配置扫描mappers文件时指定扫描*.xml文件,但是idea生成的mapper文件名不含后缀,重命名加上后缀即可。

  • No converter found for return value of type: class java.util.HashMap
  • controller层返回值无法转换成json字符串传回前端
  • 主要是因为忘记配置fastjson

    //ssm中增加在spring-mvc.xml中配置fastjson支持即可
    <!--启动SpringMvc注解功能,完成请求和注解Controller层的映射;
    启用Flash属性,发送属性到重定向的页面-->
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <!-- 配置Fastjson支持 -->
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json</value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <value>WriteMapNullValue</value>
                        <value>QuoteFieldNames</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    

  • 报错:SpringJUnit4ClassRunner requires JUnit 4.12 or higher.
  • 可能是Junit版本太低或spring-test版本太高,导致spring做测试时两个版本不搭。
  • 之前出错的版本搭配是:

    <!--单元测试-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!--集成Spring做测试必备的依赖,比如要注入Spring容器中的bean-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>5.1.3.RELEASE</version>
      <scope>test</scope>
    </dependency>
    
  • 降到4.2.4就好了

  • 报错:No mapping found for HTTP request with URI [/shirochapter12/hello1] in DispatcherServlet with name ‘spring’
  • 描述:springmvc框架的web项目访问某controller的路径时,前端404,后台报以上错误。
  • 原因:可能是spring-mvc.xml中component-scan扫描包路径没有配置好,导致DispatcherServlet不能将请求分发给对应的controller。
  • 代码实例:ideaProjects/shirochapter12/web/mvc/AnnotionController、resources/sping-mvc.xml

  • 报错:访问jsp页面时抛异常:Servlet.service() for servlet jsp threw exception java.lang.NullPointerException
  • 原因:项目jar包和tomcat的jar包冲突了,删掉jsp-api.jar即可。
  • 参考文章

  • Shiro报错:There is no session id xxx。
  • 原因:可能是没有在ehcache.xml里配置某个cache。

  • 报错:Failed to start component [StandardEngine[Tomcat]]: A child container failed。
  • 原因:第三方类库包括了servlet-api依赖,在Dependencies中查找是哪个类库引入了servlet-api,排除即可。

    <exclusions>
        <exclusion>
          <artifactId>servlet-api</artifactId>
          <groupId>javax.servlet</groupId>
        </exclusion>
    </exclusions>