67,515
社区成员
发帖
与我相关
我的任务
分享
<!-- 创建jdbc数据源 -->
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@192.168.6.25:1521:orcl"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger" ></property>
</bean>
<!-- 配置工厂sqlSsessionFactory -->
<bean id ="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="ds"></property>
<property name="mapperLocations" value="classpath:cn/voicecodes/entity/*.xml"></property>
</bean>
<bean id= "dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.2:1521:orcl"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger" ></property>
</bean>
[/quote]<!-- 配置工厂sqlSseesionFactory -->
<bean id ="sqlSseesionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" value="dataSource"></property>
<property name="mapperLocations" value="classpath:cn/voicecodes/entity/*.xml"></property>
</bean>
<bean id= "dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.2:1521:orcl"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger" ></property>
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://mybatis.org/schema/mybatis-spring
http://mybatis.org/schema/mybatis-spring.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 引入jdbc配置文件 -->
<!-- <context:property-placeholder location="classpath:db.properties" /> -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="location" value="classpath:db.properties"/>
</bean>
<!-- 创建jdbc数据源 -->
<bean id= "dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="${driverClassName}"></property>
<property name="url" value="${url}" ></property>
<property name="username" value="${username} "></property>
<property name="password" value="${password}" ></property>
</bean>
<!-- 配置工厂sqlSseesionFactory -->
<bean id = "sqlSseesionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<!-- <property name="configLocation" value="classpath:mybatis-cfg.xml"></property> -->
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations" value="classpath:cn/voicecodes/entity/*.xml"></property>
</bean>
<!-- 配置Mybatis注解 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name="basePackage" value="cn.voicecodes.dao"></property>
<!-- <property name="annotationClass" value="cn.voicecodes.MybatisRepository" ></property> -->
</bean>
<!-- 开启注解扫描 -->
<context:component-scan base-package="cn.voicecodes"/>
<!-- 开启RequestMppering注解 -->
<mvc:annotation-driven/>
<!-- -->
<bean class="org.springframework.web.servlet.view.InternalResourceView" >
<property name="prefix" value="/WEN-INF/"/>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>