SSH:dataSource配置问题

applicationContext.xml

<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"

	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	http://www.springframework.org/schema/aop 
	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd"
	xmlns:tx="http://www.springframework.org/schema/tx">
	<aop:config></aop:config>
	<!-- 打开自动装配 -->
	<context:annotation-config></context:annotation-config>
	
	<bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"
            value="com.mysql.jdbc.Driver">
        </property>
        <property name="url"
            value="jdbc:mysql://localhost:3306/mas?characterEncoding=UTF-8">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>
	

hibernate.cfg.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

	<session-factory>
		<mapping resource="cn/edu/nwsuaf/bean/Mas.hbm.xml" />
		<mapping resource="cn/edu/nwsuaf/bean/Course.hbm.xml" />
		<mapping resource="cn/edu/nwsuaf/bean/Teachingplanchange.hbm.xml" />
		<mapping resource="cn/edu/nwsuaf/bean/Highleveltalent.hbm.xml" />
		<mapping resource="cn/edu/nwsuaf/bean/Academicdegree.hbm.xml" />
		<mapping


数据源只能在一个配置文件中配置:applicationContext.xml或者hibernate.cfg.xml。


原文地址:https://www.cnblogs.com/jasonhaven/p/7355026.html