求问 springmvc+hibernate 怎么样配置多个数据库,使用时怎么注入??

WaterBai WaterBai 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在链接一个数据库是这样配置的:

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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/mydb
</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">
localhost_mysql_mydb
</property>
<mapping resource="com/pojo/User.hbm.xml" />
<mapping resource="com/pojo/Rolegroup.hbm.xml" />
<mapping resource="com/pojo/Menu.hbm.xml" />
<mapping resource="com/pojo/Role.hbm.xml" />
</session-factory>

</hibernate-configuration>


Spring配置springmvc-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:component-scan base-package="com.controller,com.dao,com.service" />

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- 配置视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>


现在想要配置两个数据库,都是MySQL的数据库。怎么样配置??sessionFactory又要用??

刚开始学,觉得好难,有没有人帮忙看下~~
...全文

相关推荐

SpringMVC+Hibernate+Spring整合实例

SpringMVC+Hibernate+Spring整合实例源码下载,很完整的例子,需要的可以下载源码学习

倔强的土豆

Spring、SpringMVC、Hibernate框架集成实战

本文还有配套的精品资源,点击获取 简介:Spring、SpringMVC和Hibernate是Java开发中常用的三大框架,它们协同工作以构建Web应用程序。本课程设计项目实战将深入探讨这三个框架的核心概念,包括Spring的DI和AOP、SpringMVC的MVC设计模式、Hibernate的ORM功能。学生将通过实践任务,掌握这些框架的整合使用,包括配置Spring容器...

銀河鐵道的企鵝

掌握Maven、Spring、SpringMVC、Hibernate的现代Java Web开发

本文还有配套的精品资源,点击获取 简介:本项目摒弃了传统的SSH框架组合,转而采用现代且流行的Maven、Spring、SpringMVC和Hibernate技术栈。通过Maven进行项目管理和依赖管理,Spring框架提供核心服务如控制反转和面向切面编程,SpringMVC负责Web应用的模型-视图-控制器模式,以及Hibernate进行数据库的ORM映射。本项目详细探讨...

温融冰

SpringMVC+Spring+HIbernate简单数据库实例.zip

SpringMVC+Spring+HIbernate简单数据库实例.zip 对应博客http://blog.csdn.net/Peng_Hong_fu/article/details/53536862

伍Wu哈Ha

Spring+SpringMVC+Hibernate框架集成详解

此文档只说明简单的框架集成,各个框架的高级特性未涉及,此文档适合有框架使用基础的开发人员查看,新手可能需要参考其他资料。

天藍若空xyy
评论 8
收藏 已收藏
分享
返回顶部
WaterBai
Java EE 67,535 成员 225,843 内容