我这里的dao层引用了多个二级包名,调用的时候,出现了下面的问题:
13:42:40.553 ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.dzmsoft.db.core.base.dao.PerpetualCalendarMapper.selectByExample] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.dzmsoft.db.core.base.dao.PerpetualCalendarMapper.selectByExample
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy94.selectByExample(Unknown Source)
at com.dzmsoft.db.core.base.service.impl.PerpetualCalendarServiceImpl.selectByExample(PerpetualCalendarServiceImpl.java:47)
at com.dzmsoft.db.core.base.service.impl.PerpetualCalendarServiceImpl$$FastClassBySpringCGLIB$$ac053baa.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
1 pom.xml中的配置
先确定mapper.xml
已经打进去了,这个应该没有问题。有必要还是检查一下jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
2 yml中的配置
这个问题应该就是dao
中的PerpetualCalendarMapper
与mapping
中的PerpetualCalendarMapper.xml
关系没有建立
mybatis:
mapper-locations: classpath*:com/tt/**/mapping/*.xml,classpath*:com/dzmsoft/**/mapping/*.xml
3 @MapperScan
这个是针对注解方式的mybatis
,我们系统中采用的是xml
,这种情况不要也可以。
参考SpringBoot整合MyBatis
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
@Slf4j
@SpringBootApplication
@ComponentScan(basePackages={"com.tt.*","com.dzmsoft.*"})
@MapperScan(basePackages={"com.tt.**.dao","com.dzmsoft.**.dao"})
@EnableDiscoveryClient
@EnableAsync
public class FayServerApplication {
public static void main(String[] args) {
try {
SpringApplication.run(FayServerApplication.class, args);
} finally {
log.info("server start finish");
}
}
}
检查日志发现
14:16:12.755 WARN org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[com.tt.**.dao, com.dzmsoft.**.dao]' package. Please check your configuration.
问题在哪里呢?如果一个基础包是没有问题的,现在多个就有问题了,待解决中。。。