junit4测试

 

 

 原始环境:spring 2.0 hibernate 3.1

 

讲讲过程

环境:JDK 必须是1.5以上  1.4不支持annoation (一些老的系统就不行了,看看怎么解决这个问题)

 

 

首先导入了Spring2.5 jar spring -test .jar 两个文件

中间遇到过一个问题就是 spring 2.0 spring 2.5如果在一起会报错,这时候把spring2.0在classpath去掉

 

其次你要更新Eclipse中自带的junit.jar文件 4.4以上版本的

 

还有注意就是数据源,由于我使用了JNDI配置中要这么写

 

 <!-- 容器datasource -->
    <bean id="dataSource"
    	class="org.springframework.jndi.JndiObjectFactoryBean">
    	<property name="jndiName">
    		<value>java:comp/env/jdbc/oracleDS</value>
    	</property>

    	<property name="resourceRef" value="true" />
    	<property name="defaultObject" ref="my-core-nojndi-ds" />
    </bean>

    <!-- fall back data-source if JNDI look up of main data-source fails -->
    <bean id="my-core-nojndi-ds"
    	class="org.apache.commons.dbcp.BasicDataSource">
    	<property name="driverClassName" value="oracle.jdbc.pool.OracleConnectionPoolDataSource" />
    	<property name="url"
    		value="jdbc:oracle:thin:whu_prd/[email protected]:1521:heer" />
    </bean>

 

代码如下: 

/**
 * <b>简述</b><br>
 * <br>
 * <code>TestUserDAO.java</code> 的主要功能是<br>
 * 
 * 
 * <p>
 * <b>特点</b>
 * <ul>
 * <li>
 * <li>
 * </ul>
 * <b>注意事项</b><br>
 * <br>
 * 
 * @author <a href="mailto:[email protected]">chenwentao</a>
 * 
 * @Date Nov 27, 2009 10:27:57 AM
 * 
 * @version 1.189, 10/21/05
 * 
 * @see
 * 
 * @since Ver 1.0
 * 
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-service.xml","classpath:/com/heer/zsu/oa/context/OaApplication.bean.xml","classpath:containerDataSource.xml","classpath:applicationContext-service.xml"})
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)
@Transactional
public class TestUserDAO extends AbstractJUnit4SpringContextTests {
	
    @Autowired
	private MeetingService meetingService;
    
    @Test
    public  void addMeeting(){
            BoaMeetingDTO  dto=new BoaMeetingDTO();
            dto.setBz("234");
            meetingService.add(dto);
    }
	
	

}

 

你可能感兴趣的:(spring,oracle,bean,Hibernate,jdbc)