Java異常解決總結
未解決問題springmvcajax-json
未解決問題已配置了註解掃描卻仍然無法注入mapper
ssm整合解決碰到的異常
IncorrectResultSizeDataAccessException
spring異常
org.springframework.dao.IncorrectResultSizeDataAccessException:Incorrect result size: expected 1, actual 5
解決:
spring jdbcquery 有的RowMapper不能出現空資料或多條資料,查詢要與方法對應
IncorrectResultSetColumnCountException
spring異常
org.springframework.jdbc.IncorrectResultSetColumnCountException:Incorrect column count: expected 1, actual 3
解決
大概意思是:查出的資料有4列,它把jdbc.queryForObject("SELECT* FROM USER WHERE ID = 1", User.class);中的第一列轉換成User.class,所以 expected1, actual 6,預期1列,但查出來的資料有4列 修改: RowMapper<User> rm =ParameterizedBeanPropertyRowMapper.newInstance(User.class); User user = (User)this.jdbcTemplate.queryForObject( "SELECT* FROM USER WHERE ID = 1", rm);
RowMapper實現類選錯
springmvc頁面servlet.init()異常,除了檢查包衝突外 檢查配置檔案是否正確
BindingException
mybatis異常
org.apache.ibatis.binding.BindingException:Invalid bound statement (not found):resultmap.one2one.mapper.OrderMapper.selectOAUByResultmap
解決
mapper.xml找不到,記住mappers標籤要用<mapperresource =”xml路徑”></mapper>
原因是在idea中,使用<mapperclass=""></mapper>和 <packagename=""></package>標籤將UserMapper.xml與UserMapper.class介面放一個包下,當執行時idea並不會將.xml拷至WEB-INF/classes中
TypeException
springmvc異常
nested exception isorg.apache.ibatis.builder.BuilderException: Error parsing SQL MapperConfiguration. Cause: org.apache.ibatis.type.TypeException: The alias 'Debug'is already mapped to the value 'com.mchange.v2.codegen.intfc.Debug'.
解決:
在此標籤中,包路徑要儘可能具體,否則可能會丟擲此異常
<typeAliases>
<package name="com.ssm.po"></package>
</typeAliases>
NoSuchBeanDefinitionException
springmvc異常
UnsatisfiedDependencyException:Error creating bean with name 'fastJsonpResponseBodyAdvice' defined in URLnested exception isorg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifyingbean of type 'java.lang.String[]' available: expected at least 1 bean whichqualifies as autowire candidate. Dependency annotations: {}
解決
在此標籤中,包路徑要儘可能具體,否則可能會丟擲此異常
<context:component-scan base-package="com.ssm.action"></context:component-scan>