1 回答
TA贡献1831条经验 获得超9个赞
不好讲,先给你看看我的配置文件吧
spring-mybaits.xml里的内容:
<!-- 定义dbcp组件DataSource -->
<bean id ="dbcp" class = "org.apache.commons.dbcp.BasicDataSource">
<property name="username" value = "root"></property>
<property name="password" value = "36963"></property>
<property name="url" value = "jdbc:mysql://localhost:3306/cloud_note?useUnicode=true&characterEncoding=utf8"></property>
<property name="driverClassName" value = "com.mysql.jdbc.Driver">
</property>
</bean>
<!--
定义SqlSessionFactory
注入dbcp,连接数据库,连接Mapper映射文件(SQL定义文件)
-->
<bean id = "ssf" class = " org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref = "dbcp"></property>
<property name="mapperLocations" value = "classpath:mapper/*.xml">
</property>
</bean>
<!--
定义MapperScannerConfigurer
注入ssf,连接
-->
<bean id = "mapperScanner"
class = "org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- dao包下都是mapper型,故不需要annocation -->
<property name="basePackage" value = "com.tedu.cloudnote.dao">
</property>
<!--
将ssf对象往里传,注入型
sqlSessionFactory可以省略不写
-->
<property name="sqlSessionFactory" ref = "ssf"></property>
</bean>
然后是spring-mvc.xml内的内容:
<!-- 定义HandlerMapping -->
<mvc:annotation-driven />
<!-- 扫描Controller,Service组件 -->
<context:component-scan
base-package="com.tedu.cloudnote"/>
还需要这么些个包:
spring mvc,mybatis,mybatis-spring,driver,dbcp,junit,spring-jdbc
- 1 回答
- 0 关注
- 749 浏览
添加回答
举报