Mapped Statements collection does not contain value for 問題的解決

來源:互聯網
上載者:User

標籤:oca   es2017   dmi   after   autowire   ram   nbsp   ssl   mini   

在做SSM項目的時候,遇到MyBatis拋出的一個異常:

Mapped Statements collection does not contain value for org.lyk.vo.mapping.NewsNS.findById.

2017-09-01 21:03:48,979 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - Refreshing org[email protected]108d02eb: startup date [Fri Sep 01 21:03:48 CST 2017]; root of context hierarchy2017-09-01 21:03:49,019 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from class path resource [applicationContext.xml]2017-09-01 21:03:49,352 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - JSR-330 ‘javax.inject.Inject‘ annotation found and supported for autowiring2017-09-01 21:03:49,433 INFO [com.mchange.v2.log.MLog] - MLog clients using log4j logging.2017-09-01 21:03:49,523 INFO [com.mchange.v2.c3p0.C3P0Registry] - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]2017-09-01 21:03:49,736 INFO [com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource] - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 4mdhs29qh2pjh31t4weot|429d486d, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 4mdhs29qh2pjh31t4weot|429d486d, idleConnectionTestPeriod -> 0, initialPoolSize -> 10, jdbcUrl -> jdbc:mysql://localhost:3306/mldn, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]2017-09-01 21:03:49,968 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] - Mapped "{[/pages/member/insert],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.portlet.ModelAndView org.lyk.action.MemberAction.insert()2017-09-01 21:03:50,060 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] - Looking for @ControllerAdvice: org[email protected]108d02eb: startup date [Fri Sep 01 21:03:48 CST 2017]; root of context hierarchy2017-09-01 21:03:50,099 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] - Looking for @ControllerAdvice: org[email protected]108d02eb: startup date [Fri Sep 01 21:03:48 CST 2017]; root of context hierarchy2017-09-01 21:03:50,147 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - Mapped URL path [/**] onto handler ‘org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0‘org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.lyk.vo.mapping.NewsNS.findById### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.lyk.vo.mapping.NewsNS.findById    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:368)    at com.sun.proxy.$Proxy12.selectOne(Unknown Source)    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)    at org.lyk.dao.impl.NewsDAOImpl.findById(NewsDAOImpl.java:60)    at org.lyk.dao.impl.NewsDAOImpl.findById(NewsDAOImpl.java:1)    at org.lyk.service.impl.NewsServiceImpl.get(NewsServiceImpl.java:57)    at org.lyk.main.Hello.main(Hello.java:37)Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.lyk.vo.mapping.NewsNS.findById### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.lyk.vo.mapping.NewsNS.findById    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:606)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)    ... 6 moreCaused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.lyk.vo.mapping.NewsNS.findById    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:791)    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:631)    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:624)    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:103)    ... 13 more

根本原因是mybatis.cfg.xml設定檔缺少了對Mapper.xml的引用。增加如下配置就可以解決該問題了。

https://stackoverflow.com/questions/14219558/mybatis-illegalargumentexception-mapped-statements-collection-does-not-contain

 

 

 

PS: 該問題也有可能是由於mapper檔案裡面沒有定義該操作。

Mapped Statements collection does not contain value for 問題的解決

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.