Besides Mybatis3:invalid bound statement (not found)

Source: Internet
Author: User



Novice use mybatis3 of sadness, should also only novice to understand, online a bunch of solutions to solve the anomaly do not work, mentality is not good, hit the computer is possible, fortunately, my mentality can also, admit that their knowledge is not enough, only anger and learning, hehe, a little more.



Recently skilled SPRINGMVC+MYBATIS3 development framework, in the development environment encountered such as the title of the problem, code layered or ordinary controller, service, service Impl, mapper layer, Then use annotations to inject beans, annotated with JSR-330 specifications, similar to @inject, @Named.



Introduction cut here, read the newspaper wrong:


INFO: JSR-330 ‘javax.inject.Inject‘ annotation found and supported for autowiring
Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.join.stump.site.service.MenuService.queryMenuList
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:43)
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
	at com.sun.proxy.$Proxy12.queryMenuList(Unknown Source)
	at com.join.stump.site.service.impl.MenuServiceImpl.main(MenuServiceImpl.java:25)


Call Method:


public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "stump-core-config.xml" });
		MenuService menuService = (MenuService) context
				.getBean("menuService");
		System.err.println("menuService:"+menuService.queryMenuList(null));
	}


Obviously, when calling the service method, there are two places that might make you wonder,



1, why reported invalid bound statement (not found): com.join.stump.site.service.MenuService.queryMenuList



2. Why the Service object type is Org.apache.ibatis.binding.MapperProxy



On the first question, the second question can be explained, because it is org.apache.ibatis.binding.MapperProxy This SQL is not available in the SQL mapping file using com.join.stump.site.service.MenuService.queryMenuList in MyBatis, so it is an error.



Then why there is a second problem, I also do not ride elder sister (intentional), after a party toss, see mybatis-spring official online paragraph, feel enlightened, try to adjust the next there is no problem. This question is very much related to my MyBatis configuration file. First look at the configuration before the error:


<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.join.stump" />
	</bean>


Then look at the resolved configuration:


<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.join.stump.site.mapper,com.join.stump.base.mapper" />
	</bean>




Did you notice the difference? Then I give a description of the official website:
Mapperscannerconfigurer supports filtering by creating a mapper from the specified creation interface or annotations. The Annotationclass property specifies the name of the note to look for. The Markerinterface property specifies the parent interface to look for. If both are specified, the mapper added to the interface will match the two criteria. by default, both properties are null, so all interfaces given in the base package can be loaded as mappers .
Well, you should be able to think of something, okay, I'll get it straight, Error in the configuration of Basepackage with Com.join.stump, so mapperscannerconfigurer do scan, the service also swept in, so, now can ride elder sister.





Besides Mybatis3:invalid bound statement (not found)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.