Code Bye

Mybatis+SpringMVC 封装实体时java.lang.NoSuchMethodException

sql语句执行了,但是在封装实体时报错

DEBUG 2014-09-23 00:46:24,721 org.apache.ibatis.logging.slf4j.Slf4jImpl: ooo Using Connection [org.apache.commons.dbcp.PoolableConnection@97aaa6]
DEBUG 2014-09-23 00:46:24,721 org.apache.ibatis.logging.slf4j.Slf4jImpl: ==>  Preparing: select a.agentid,a.aname,a.email,a.linktel,a.partname,a.anumber from agent a 
DEBUG 2014-09-23 00:46:24,722 org.apache.ibatis.logging.slf4j.Slf4jImpl: ==> Parameters: 
严重: Servlet.service() for servlet [springmvc] in context with path [/HomeLink] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Error instantiating interface com.kker.dao.AgentDao with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.kker.dao.AgentDao.<init>()] with root cause

	at java.lang.Class.getConstructor0(Class.java:2706)
	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:57)
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:45)
	at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:38)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.createResultObject(FastResultSetHandler.java:376)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.createResultObject(FastResultSetHandler.java:355)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.getRowValue(FastResultSetHandler.java:255)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleRowValues(FastResultSetHandler.java:214)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSet(FastResultSetHandler.java:186)
	at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:152)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:91)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)
	at $Proxy9.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:188)
	at com.kker.dao.impl.AgentDaoImpl.queryAgents2(AgentDaoImpl.java:104)
	at com.kker.biz.impl.AgentBizImpl.queryAgents2(AgentBizImpl.java:108)
	at com.kker.action.AgentController.queryAgents(AgentController.java:264)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)

以下是我的xml文件

<resultMap type="com.kker.dao.AgentDao" id="agentMap">
		<id property="agentId" column="agentid" javaType="java.lang.Integer"/>
		<result property="aname" column="aname" javaType="java.lang.String"/>
		<result property="email" column="email" javaType="java.lang.String"/>
		<result property="linktel" column="linktel" javaType="java.lang.String"/>
		<result property="anumber" column="anumber" javaType="java.lang.String"/>
		<result property="partname" column="partname" javaType="java.lang.String"/>
		<collection property="businessareas" ofType="com.kker.entity.Businessarea" column="agentid" select="getbu">
		</collection> 
	</resultMap>
	<resultMap type="com.kker.entity.Businessarea" id="bu">
		<id property="shopId" column="shopid"/>
		<result property="chengquId" column="chengquid"/>
		<result property="shopName" column="shopname"/>
	</resultMap>
	<select id="queryAgents2" resultMap="agentMap">
		select a.agentid,a.aname,a.email,a.linktel,a.partname,a.anumber from agent a
	</select>
	<select id="getbu" resultMap="bu" parameterType="int">
		select d.shopid,d.chengquid,d.shopname 
		from CommunityAgent b,neighborhood c,businessArea d 
		where b.districtid=c.districtid and d.shopid=c.shopid and b.agentid=#{agentId}
	</select>
	 <select id="queryAll" resultType="Agent">
	 		select agentId,aname from Agent
	 </select>

调用语句这样的

 List<Agent> alist = this.getSqlSession().selectList("com.kker.dao.AgentDao.queryAgents2");

实在找不出原因了

这是那些类

20分
难道是com.kker.dao.AgentDao没有默认的公共构造函数?

20分
Cause: java.lang.NoSuchMethodException: com.kker.dao.AgentDao.<init>()

1、看看是不是构造方法的问题

2、看看是不是jar包引起的构造方法冲突

引用 3 楼 shijing266 的回复:

Cause: java.lang.NoSuchMethodException: com.kker.dao.AgentDao.<init>()

1、看看是不是构造方法的问题

2、看看是不是jar包引起的构造方法冲突

   是这个原因
<resultMap type=”com.kker.dao.AgentDao” id=”agentMap”>
  type应该是我的实体类的,粘贴复制顺手了,,,, 


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Mybatis+SpringMVC 封装实体时java.lang.NoSuchMethodException