我用Intellij Idea开发的,所以配置文件中出错会标识红色,spring-service.xml中的ref="IStudentDao"部分出错。
另外我用Maven做的项目管理,不知道是不是配置文件放置的路径有问题。附上我的项目目录结构:
部署到Tomcat上启动后,报No adapter for handler [com.bruceliao.controller.StudentController@12bc3bf8]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
Mybatis配置文件:
<configuration>
<!--别名-->
<typeAliases>
<package name="com.bruceliao.beans"/>
</typeAliases>
<!--Mapper的位置-->
<mappers>
<package name="com.bruceliao.dao"/>
</mappers>
</configuration>
Spring配置文件:
spring-mybatis.xml
<!--注册sqlSessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<!--生成Dao代理对象-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<property name="basePackage" value="com.bruceliao.dao"/>
</bean>
spring-service.xml
<!--注册Service-->
<bean id="studentService" class="com.bruceliao.service.impl.StudentServiceImpl">
<property name="studentDao" ref="IStudentDao"/>
</bean>
spring-mvc.xml
<bean id="/view/login.do" class="com.bruceliao.controller.StudentController">
<property name="studentService" ref="studentService"/>
</bean>