练手时发现个问题,路径404,各种检查发现,多加了一层<context:component-scan base-package="com.yanan.controller"/>写成了<context:component-scan base-package="com.yanan.*.controller"/>
解决后,发现service注入失败
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yanan.service.UserService.getListUsers
排查发现,扫描时
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yanan.mapper"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>成功<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yanan.*"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean>失败由此可见,扫描时*不是万能的,尽量指明具体包。
搭建环境是springmvc+mybatis+maven多模块。或许多模块下报的命名有关?还是本身扫描的包不能太宽泛?理解不深,请各位读者多多指教