当前位置: 代码迷 >> Java Web开发 >> 请教spring如何同时配置jdbc和hibernate链接?
  详细解决方案

请教spring如何同时配置jdbc和hibernate链接?

热度:7415   发布时间:2016-04-10 22:58:43.0
请问spring怎么同时配置jdbc和hibernate链接???
我的代码:
<!-- dataSource1-hibernate -->	
<bean id="dataSource1_hibernate" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.springframework.jdbc.datasource.DriverManagerDataSource</value>
</property>
<!-- set-Proxool -->
<property name="url" value="proxool.alias1_hibernate"></property>
</bean>

<!--  -->
<bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource1_hibernate"/>
</bean>

<!-- sessionFactory1  org.springframework.orm.hibernate3.LocalSessionFactoryBean -->
<bean id="sessionFactory"  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
<property name="dataSource">
<ref local="dataSource1_hibernate"/>
</property>
<property name="mappingLocations">
<list>
<!-- load jbpm beans files -->
<!--
<value>classpath:jbpm.execution.hbm.xml</value>
<value>classpath:jbpm.history.hbm.xml</value>
<value>classpath:jbpm.identity.hbm.xml</value>
<value>classpath:jbpm.repository.hbm.xml</value>
<value>classpath:jbpm.task.hbm.xml</value>
-->
<!-- actomatic scan your define of bussiness beans 
<value>classpath:com/kaide/workflow/bean/*/*.hbm.xml</value>
-->
</list>
</property>

<property name="packagesToScan">
<value>com.kaide.bean</value>
</property>

hibernate可以正常运行,但是我的jdbc测试的时候总是报错:空指针异常
package com.kaide.kframe;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;


@Scope("prototype")
@Repository
public class JdbcConnection{

@Autowired
private JdbcTemplate jdbcTemplate;

/*public void setDataSource(DataSource dataSource){

this.jdbcTemplate = new JdbcTemplate(dataSource);
}
*/

public void queryTest(){

 List<Map<String,Object>> list =
  jdbcTemplate.queryForList("select id,pId from tree");
 
 
 System.out.println(list.size());
}



}


高分求大神们指点下啊!!!!!!

------解决方案--------------------
你配2个sqlSessionFactory

------解决方案--------------------
http://m.blog.csdn.net/blog/zhangliao613/8277343
  相关解决方案