当前位置:编程学习 > JAVA >>

hibernate和spring的配置文件是分开时,在spring配置中怎么使用dataSource?

SpringSecurity怎么关联dataSource?因为项目使用了jbpm工作流框架,所以我的hibernate和spring的配置文件是分开的,不是共用spring的配置文件,那我使用SpringSecurity连接数据库的时候,那个dataSource怎么得到? --------------------编程问答-------------------- 唉,第一次提问就没有人理我 --------------------编程问答-------------------- 给你个例子分开之后不再配置dataSource了。 --------------------编程问答--------------------
引用 2 楼 peng_hao1988 的回复:
给你个例子分开之后不再配置dataSource了。

现在情况是在spring配置文件中配置SpringSecurity框架的配置时,需要使用dataSource ,而因为项目又需要用到工作流框架,所有原来就已经把hibernate和spring的配置文件是分开了。 --------------------编程问答-------------------- 首先在hibernate.cfg.xml文件中配置数据库连接和映射的文件 例如:<mapping resource="com/cywl/logon/entity/TreeFunction.hbm.xml" />文件


然后在spring配置文件中配置hibernate.cfg.xml文件。

                 <property name="configLocation">
  <value>classpath:hibernate.cfg.xml</value>
  </property>
--------------------编程问答-------------------- hibernate.cfg.xml 要配置库和映射文件 --------------------编程问答-------------------- 方法很多,proloader这个hibernate配置文件,直接使用database就行。 --------------------编程问答--------------------
引用 6 楼 fangmingshijie 的回复:
方法很多,proloader这个hibernate配置文件,直接使用database就行。

能详细说一下吗?在hibernate和spring的配置文件分开后,spring里没有了dataSource ,可是现在要在spring中使用dataSource ,有什么办法?
--------------------编程问答-------------------- 你既然分开了,在spring配置文件中,你肯定要配置一个datasource --------------------编程问答-------------------- --------------------编程问答-------------------- 在配置spring和hibernat的时候可以让它自动和在一起
会在spring配置文件中出现bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>entity/BizClaimVoucherDetalt.hbm.xml</value>
<value>entity/BizCheckResult.hbm.xml</value>
<value>entity/SysPosition.hbm.xml</value>
<value>entity/SysEmployee.hbm.xml</value>
<value>entity/SysDepartment.hbm.xml</value>
<value>entity/BizClaimVoucher.hbm.xml</value></list>
</property></bean> --------------------编程问答-------------------- 谢谢大家了,你们都没有理解好我遇到的情况,现在我已经决定不用jbpm了,所以也算解决问题了
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,