Junit 测试SSH框架时使用了propertyConfigurer 读取jdbc.properties文件,Cannot load JDBC driver class
Spring的配置文件===================<beanid="propertyConfigurer"class="org.springframework....
Spring 的配置文件===================
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:configuration/jdbc/jdbc.properties</value>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
......
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc0.driverClassName}"/>
<property name="url" value="${jdbc0.url}" />
<property name="username" value="${jdbc0.username}" />
<property name="password" value="${jdbc0.password}" />
</bean>
.......
DAO
=========
public interface ExtTestService {
public List getUserList();
public void addUser(SfUser sfUser) ;
}
DAOImpl
======
....
public void addUser(SfUser sfUser) {
getHibernateDAO().insertByRecord(sfUser);
}
....
使用Junit测试的代码
public class BeanTest extends TestCase {
String[] locations ="classpath*:configuration/spring/applicationContext*.xml",
"com/foxconn/*/**/configuration/spring-platform-module.xml" };
ApplicationContext context = new ClassPathXmlApplicationContext(locations);
@Test
public void testCase() throws Exception {
ExtTestService extTestService = (ExtTestService) context
.getBean("extTestService");
List list = extTestService.getUserList();//这个方法可以执行,DAO的配置没问题
for (Object o : list) {
System.out.println(o);
}
//实体类SfUser
SfUser user = new SfUser();
user.setCreateDate(new Date());
String pass = MD5Utils.getMD5DigestBase64("password");
user.setPassword(pass);
user.setType("employee");
user.setUserid("1001");
user.setUsername("1001");
user.setValidFlag("1");
extTestService.addUser(user);//使用hibernate持久报异常
}
}
我的包 展开
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:configuration/jdbc/jdbc.properties</value>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
......
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc0.driverClassName}"/>
<property name="url" value="${jdbc0.url}" />
<property name="username" value="${jdbc0.username}" />
<property name="password" value="${jdbc0.password}" />
</bean>
.......
DAO
=========
public interface ExtTestService {
public List getUserList();
public void addUser(SfUser sfUser) ;
}
DAOImpl
======
....
public void addUser(SfUser sfUser) {
getHibernateDAO().insertByRecord(sfUser);
}
....
使用Junit测试的代码
public class BeanTest extends TestCase {
String[] locations ="classpath*:configuration/spring/applicationContext*.xml",
"com/foxconn/*/**/configuration/spring-platform-module.xml" };
ApplicationContext context = new ClassPathXmlApplicationContext(locations);
@Test
public void testCase() throws Exception {
ExtTestService extTestService = (ExtTestService) context
.getBean("extTestService");
List list = extTestService.getUserList();//这个方法可以执行,DAO的配置没问题
for (Object o : list) {
System.out.println(o);
}
//实体类SfUser
SfUser user = new SfUser();
user.setCreateDate(new Date());
String pass = MD5Utils.getMD5DigestBase64("password");
user.setPassword(pass);
user.setType("employee");
user.setUserid("1001");
user.setUsername("1001");
user.setValidFlag("1");
extTestService.addUser(user);//使用hibernate持久报异常
}
}
我的包 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询