Spring-Template模版类
文章平均质量分 64
Spring-Template模板类
OkidoGreen
这个作者很懒,什么都没留下…
展开
-
RestTemplate请求Could not extract response: no suitable HttpMessageConverter found for response type..
使用 Spring Boot 写项目,需要用到微信接口获取用户信息。在 Jessey 和 Spring RestTemplate 两个 Rest 客户端中,想到尽量不引入更多的东西,然后就选择了 Spring RestTemplate 作为 网络请求的 Client,然后就被微信接口摆了一道,然后踩了一个 RestTemplate 的坑。二、第一个坑:被微信摆了一道报错信息是:org.springframework.web.client.RestClientException: Could n转载 2021-05-07 10:49:40 · 5377 阅读 · 1 评论 -
httpclient的两个重要的参数maxPerRoute及MaxTotal
httpclient封装了java中进行http网络请求的底层实现,是一个被广泛使用的组件。httpclient是支持池化机制的,这两个参数就是表示池化设置的。服务之间发送http请求常用的有Apache的Fluent以及spring的restTemplate等Apache的Fluent,以及spring的restTemplate都是对httpclient进行了封装以Apache的Fluent为例说明其Executor类 /*** An Executor for fluent.转载 2021-01-15 13:35:42 · 2813 阅读 · 0 评论 -
RestTemplate + HttpClient 调用Https 接口
配置项: //设置整个连接池最大连接数 根据自己的场景决定 private int maxTotal; //路由是对maxTotal的细分 private int defaultMaxPerRoute; //服务器返回数据(response)的时间,超过该时间抛出read timeout private int socketTimeout; //连接上服务器(握手成功)的时间,超出该时间抛出connect timeout privat原创 2021-01-05 14:00:03 · 328 阅读 · 0 评论 -
使用spring RestTemplate进行rest接口测试
使用spring RestTemplate进行rest接口测试Rest代表性状态传输(Representational State Transfer,REST)。由于约定大于配置的讨论,主流 Web 2.0 服务提供者(包括 Yahoo、Google 和 Facebook)采用了更易于使用、面向资源的模型来公开其服务,而放弃了SOAP或者WSDL。RestTemplate转载 2017-07-03 16:07:19 · 2530 阅读 · 0 评论 -
HibernateTemplate 自动事务
使用HibernateTemplate时,不显示的声明事务管理,照样能对数据库做CURD。 这是因为在没有声明事务时,HibernateTemplate是默认自动提交事务的。 因此如果在业务代码中,只涉及到一次数据库操作时默认自动事务提交已经足够,如果多次数据库操作则需要做事务声明。转载 2013-12-05 10:54:10 · 4101 阅读 · 1 评论 -
Spring JDBC 常用批量操作及插入操作
Spring 常用批量操作有很多种方法,但是大多数人知道一种或者其中的几种,先总结一些spring JDBC常用的批量操作的方法及其效率;使用JDBCTemplate 进行基本的批量操作这种方法是网上大多数采用的方法, 但是在实际应用中我感觉不太方便,这个方法能不能做成一个通用的接口呢?一直没有仔细研究过 public class JdbcActorDao转载 2016-12-16 13:18:58 · 6978 阅读 · 0 评论 -
利用GeneratedKeyHolder获得新建数据主键值
Spring利用GeneratedKeyHolder,提供了一个可以返回新增记录对应主键值的方法: int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) Spring为KeyHolder接口指代了一个通用的实现类GeneratedKeyHolder,该类返回新增记录时的自增长主键值。假设转载 2016-07-11 17:31:00 · 2827 阅读 · 0 评论 -
hibernate -- 分页模糊查询中setParameter 和setParameterList
在分页模糊查询中碰到setParameter 和setParameterList这两个方法setParameter以前就只会用setParameter(int arg,String str),我用到了from table A where 1=1 and ... like ? 还可以用另外一种方法: setParameter(String arg0, Object arg1)但是转载 2014-12-11 17:02:18 · 5653 阅读 · 0 评论 -
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional
getHibernateTemplate().getSessionFactory().getCurrentSession()的意思是得到当前线程绑定的session,而当前线程绑定的session是通过当前的事务产生的,如果你没有配置事务的话,当前线程threadlocal中就不存在session,这样就出现no session错误。而execute方法,看源码HibernateTempl转载 2013-01-29 17:01:22 · 4231 阅读 · 0 评论 -
使用Spring的HibernateDaoSupport时的getSession()3个方法的区别
在Hibernate中的两种session打开方式this.getsession实际上是调用了父类中的方法获得session。使用spring管理hibernate的SessionFactory的时候,这个方法会从session池中拿出一session.这样做有可能有问题,就是超session池连接数的时候,spring无法自动的关闭session。 不推荐使用this.getHi转载 2013-01-29 20:27:07 · 4489 阅读 · 0 评论