天天看点

数据集操作

代码运行报错:

----------> Parent Classloader:
java.net.URLClassLoader@1c53fd30
:
java.lang.ClassNotFoundException: org.springframework.dao.TransientDataAccessResourceException
八月 10, 2018 5:45:28 下午 com.caucho.hessian.io.SerializerFactory getDeserializer
警告: Hessian/Burlap: 'org.springframework.dao.TransientDataAccessResourceException' is an unknown class in ParallelWebappClassLoader
  context: cc-web
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@1c53fd30
:
java.lang.ClassNotFoundException: org.springframework.dao.TransientDataAccessResourceException
com.weibo.api.motan.exception.MotanServiceException: error_message: biz exception cause is throwable error:class java.lang.Throwable, errmsg:PreparedStatementCallback; SQL [SELECT `free_pricing` FROM `account` WHERE `account_id`=?]; Before start of result set, status: 503, error_code: 10001,r=null
	at com.weibo.api.motan.proxy.RefererInvocationHandler.invoke(RefererInvocationHandler.java:127)
	at com.sun.proxy.$Proxy71.getFreePricingStatus(Unknown Source)
	at com.btzh.resource.ProfileResource.toCopyright(ProfileResource.java:285)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)           

代码是很简单的一个sql查询:

@Override
	public YesOrNo getFreePricingStatus(Integer accountId) {
		return jdbcTemplate.query("SELECT `free_pricing` FROM `account` WHERE `account_id`=?", new Object[] { accountId }, new ResultSetExtractor<YesOrNo>() {
			@Override
			public YesOrNo extractData(ResultSet rs) throws SQLException, DataAccessException {
				return YesOrNo.getByValue(rs.getInt("free_pricing"));
			}
		});
	}           

单元测试没有任何问题, 放到项目中运行就出现上面的报错. 后来想是不是因为缺少rs.next(), 导致指针仍然在第一个元素的前一个位置, 导致指针没有下移, 改了下:

@Override
	public YesOrNo getFreePricingStatus(Integer accountId) {
		return jdbcTemplate.query("SELECT `free_pricing` FROM `account` WHERE `account_id`=?", new Object[] { accountId }, new ResultSetExtractor<YesOrNo>() {
			@Override
			public YesOrNo extractData(ResultSet rs) throws SQLException, DataAccessException {
				if (rs.next()) {
					return YesOrNo.getByValue(rs.getInt("free_pricing"));
				}
				return YesOrNo.NO;
			}
		});
	}           

好了. 但是没想清楚为什么单元测试没有报错, 待续.