spring 异常记录

1、异常:

java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap
 at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:188)
 at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:173)
 at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
 at

解决方案:https://wiki.scn.sap.com/wiki/display/Java/No+converter+found+for+return+value+of+type

Add the following dependency in pom.xml and issue will be resolved:
<dependency>
   <groupId>com.fasterxml.jackson.core</groupId>
   <artifactId>jackson-databind</artifactId>
   <version>2.5.0</version>
  </dependency>
 
2、spring默认线程不安全
若要线程安全,需要在controller类上方设置:@Scope("prototype")
3、spring 4.0+response header contentType返回的编码为ISO-8859-1,如果全局设置编码需要在ApplicationContext-mvc.xml中设置:
 <mvc:annotation-driven>
  <mvc:message-converters>
   <!-- default StringHttpMessageConverter, solve encoding problem. eg.response header contentType -->
   <bean class="org.springframework.http.converter.StringHttpMessageConverter">
    <constructor-arg value="UTF-8" />
    <property name="writeAcceptCharset" value="false" />
   </bean>
  </mvc:message-converters>
 </mvc:annotation-driven>
View Code

单独设置header,需要在responseBody上设置produces = "application/json; charset=UTF-8"
4、mysql驱动,在6.0上已经变为com.mysql.cj.jdbc.Driver,时间在16年10份前后,需要对比mysql5.6.13安装包版本无法加载驱动,猜测需要升级安装包至6.0以上。

5、待定:目前项目的分页控件,破坏了ehcache的缓存机制,ehcache缓存以mapping中的sql语句为key,分页控件通过拦截器拦截sql,从数据库获得总数据,然后计算页数,与数据总数,然后拼接sql+limit xx,10。想想办法能否实现以“sql+limit xx,10”为key。或者其他方式(从ehcache中获取总数?)。不过从druid日志来看,不对mybatis mapping文件中加缓存,连续触发10次查询操作,sql打印了3~5次不等。猜测druid连接池也起到了一定的缓存作用。目前暂时将带有分页控件的mapping文件,取消ehcache缓存。

5、contoller中使用单利,会出现问题吗?
原文地址:https://www.cnblogs.com/shixm/p/5931252.html