1.Service接口实现类要加上正确的@Service注解
import org.springframework.stereotype.Service;
2.注意spring容器的扫描和SpringMVC容器的扫描不要错
例子
spring
<!-- 配置扫描路径 -->
<context:component-scan base-package="com.biao.*" use-default-filters="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
SpringMVC
<!-- 扫描路径的配置 -->
<context:component-scan base-package="com.biao" use-default-filters="false">
<context:include-filter
type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
3.注意要在web.xml的配置文件中导入spring和mybatis的配置文件
我的项目配置文件名都是以 applicationContext- 开头的,所以我这里用 applicationContext-*
<!--配置Spring,初始化spring容器-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>