Reasons for BindingException in SSM with maven Integration

Posted by vbnullchar on Fri, 10 May 2019 02:16:02 +0200

Reasons for generating org.apache.ibatis.binding.BindingException

When I was doing SSM integration, I made this mistake:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): jgsu.clong.mapper.SpuMapper.insert_spu
	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.$Proxy16.insert_spu(Unknown Source)
	at jgsu.clong.service.imle.SpuServiceImpl.save_spu(SpuServiceImpl.java:22)
	at jgsu.clong.controller.SpuController.spu_add(SpuController.java:34)
	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.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	.........
    ........

Encountering this problem, I have not found it for a long time, Baidu has not found a lot of how to solve it. I checked this mistake again in a few days and saw a solution. First, let's see what the mistake may be caused by?

Interpretation: org.apache.ibatis.binding.bindingexception control: invalid declaration (instead of finding jgsu. clong. mapper. SPU mapper. insert SPU): the method jgsu.clong.mapper.SpuMapper.insert_spu could not be found

     Spring injection here means that your interface has been successfully scanned, but when Spring attempts to inject an implementation class of a proxy (MyBatista implementation), it fails to work properly. There are several possible scenarios here.
The interface has been scanned, but the proxy object is not found. Even if you try to inject, you inject an incorrect object (probably null).
The interface has been scanned, the proxy object has been found and injected into the interface, but when a specific method is called, it cannot be used (other methods may be normal).

1. Is the mapper interface and mapper.xml in the same package? Is the name the same (only with different suffixes)?
For example, the interface name is UserMapper.java; the corresponding xml should be UserMapper.xml
Does the namespace of mapper.xml correspond to the package name of the mapper interface?
For example, if the package name of your interface is com.abc.dao and the interface name is NameMapper.java, then the namespace of your mapper.xml should be jgsu.clong.UserMapper.
2. The method name of the interface is the same as the id of an sql tag in xml
For example, the interface method List findAll(); then, there must be one in the corresponding xml

​ ****

3. If the return value List set in the interface (I don't know other collections are also), then the configuration in XML should use resultMap as far as possible (to ensure that the resultMap configuration is correct), not use resultType. Finally, if your project is a maven project, please go to the directory of the interface after compilation to see, it is likely that there is no corresponding XML file produced, because Maven defaults to be No. Compiled, so you need to add a paragraph in your 4, 4, pom.xml:


src/main/java

**/*.xml

true

I found my own mistakes and read the method name and configuration file many times. I thought it was the above problem, which led to a waste of time. Finally, it was found that the problem was 4.

Topics: Java xml Apache Spring