org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cn.o2oweb.test.UserinfoTest': Unsatisfied dependency expressed through bean property 'dataSource': Set this property value or disable dependency checking for this bean.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1039)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:858)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:274)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:179)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:158)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:76)
at junit.framework.TestCase.runBare(TestCase.java:125)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1039)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:858)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:274)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.injectDependencies(AbstractDependencyInjectionSpringContextTests.java:179)
at org.springframework.test.AbstractDependencyInjectionSpringContextTests.prepareTestInstance(AbstractDependencyInjectionSpringContextTests.java:158)
at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:76)
at junit.framework.TestCase.runBare(TestCase.java:125)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
<?xml version="1.0" encoding="GBK"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost/o2oweb"/>
<property name="user" value="o2oweb"/>
<property name="password" value="o2oweb"/>
<property name="maxPoolSize" value="20"/>
<property name="minPoolSize" value="1"/>
<property name="initialPoolSize" value="1"/>
<property name="maxIdleTime" value="20"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value></value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
</beans>
dao。xml<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="daoTemplate" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <bean id="fondinfoDao" class="cn.o2oweb.dao.web.impl.FondInfoDaoImpl"
parent="daoTemplate" /> <bean id="goodsinfoDao" class="cn.o2oweb.dao.web.impl.GoodsInfoDaoImpl"
parent="daoTemplate" />
<bean id="unusualgoodsDao" class="cn.o2oweb.dao.web.impl.UnusualGoodsDaoImpl"
parent="daoTemplate" /> <bean id="useractiveDao" class="cn.o2oweb.dao.web.impl.UserActiveDaoImpl"
parent="daoTemplate" />
<bean id="userFondinfoDao" class="cn.o2oweb.dao.web.impl.UserFondInfoDaoImpl"
parent="daoTemplate" />
<bean id="userinfoDao" class="cn.o2oweb.dao.web.impl.UserInfoDaoImpl"
parent="daoTemplate" />
</beans>
import java.util.List;import org.apache.log4j.Logger;import junit.framework.TestCase;
import junit.textui.TestRunner;import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;import cn.o2oweb.dao.web.IUserInfoDao;
public class UserinfoTest extends AbstractTransactionalDataSourceSpringContextTests
{
static Logger log = Logger.getLogger(UserinfoTest.class.getName());
IUserInfoDao userInfoDao; public String[] getConfigLocations()
{
String[] configLocations = {"daoContext.xml","applicationContext.xml"};
return configLocations;
}
public void onSetUpInTransaction()
{
userInfoDao = (IUserInfoDao)applicationContext.getBean("userinfoDao");
}
public void onTearDownInTransaction()
{
userInfoDao = null;
} public void testFindItemByKind()
{
String hql="from Userinfo ";
List l = userInfoDao.getDataForPage(hql, 1, 3);
//log.info(l.size());
//System.out.println(jdbcTemplate.queryForInt("select count(*) from Userinfo "));
assertEquals(0,0);
} public static void main(String[] args)
{
TestRunner.run(UserinfoTest.class);
}
}
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="cn.o2oweb.model.web.Userinfo" table="userinfo" catalog="o2oweb">
<id name="userId" type="java.lang.String">
<column name="UserId" length="24" />
<generator class="assigned" />
</id>
<property name="userName" type="java.lang.String">
<column name="UserName" length="20" not-null="true">
<comment>姓名</comment>
</column>
</property>
<property name="userPass" type="java.lang.String">
<column name="UserPass" length="32" not-null="true">
<comment>密码</comment>
</column>
</property>
<property name="userEmail" type="java.lang.String">
<column name="UserEmail" length="64" not-null="true">
<comment>电子邮件</comment>
</column>
</property>
<property name="userIntro" type="java.lang.String">
<column name="UserIntro">
<comment>用户介绍</comment>
</column>
</property>
<property name="userAddress" type="java.lang.String">
<column name="UserAddress" length="256">
<comment>地址</comment>
</column>
</property>
<property name="userPicture" type="java.lang.String">
<column name="UserPicture" length="1024">
<comment>图像</comment>
</column>
</property>
<property name="userBirth" type="java.util.Date">
<column name="UserBirth" length="0">
<comment>生日</comment>
</column>
</property>
<property name="userIsActive" type="java.lang.Boolean">
<column name="UserIsActive">
<comment>用户激活</comment>
</column>
</property>
<property name="userPower" type="java.lang.Integer">
<column name="UserPower">
<comment>用户权限</comment>
</column>
</property>
<set name="useractives" inverse="true">
<key>
<column name="UserId" length="24" not-null="true" unique="true">
<comment>用户id</comment>
</column>
</key>
<one-to-many class="cn.o2oweb.model.web.Useractive" />
</set>
<set name="userfondinfos" inverse="true">
<key>
<column name="UserId" length="24" not-null="true" />
</key>
<one-to-many class="cn.o2oweb.model.web.Userfondinfo" />
</set>
<set name="useractives_1" inverse="true">
<key>
<column name="UserId" length="24" not-null="true" unique="true">
<comment>用户id</comment>
</column>
</key>
<one-to-many class="cn.o2oweb.model.web.Useractive" />
</set>
<set name="goodsinfos" inverse="true">
<key>
<column name="UserId" length="24" not-null="true">
<comment>用户Id</comment>
</column>
</key>
<one-to-many class="cn.o2oweb.model.web.Goodsinfo" />
</set>
<set name="userfondinfos_1" inverse="true">
<key>
<column name="UserId" length="24" not-null="true" />
</key>
<one-to-many class="cn.o2oweb.model.web.Userfondinfo" />
</set>
<set name="goodsinfos_1" inverse="true">
<key>
<column name="UserId" length="24" not-null="true">
<comment>用户Id</comment>
</column>
</key>
<one-to-many class="cn.o2oweb.model.web.Goodsinfo" />
</set>
</class>
</hibernate-mapping>
class
package cn.o2oweb.model.web;import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* Userinfo entity. @author MyEclipse Persistence Tools
*/public class Userinfo implements java.io.Serializable {
// Fields private String userId;
private String userName;
private String userPass;
private String userEmail;
private String userIntro;
private String userAddress;
private String userPicture;
private Date userBirth;
private Boolean userIsActive;
private Integer userPower;
private Set useractives = new HashSet(0);
private Set userfondinfos = new HashSet(0);
private Set useractives_1 = new HashSet(0);
private Set goodsinfos = new HashSet(0);
private Set userfondinfos_1 = new HashSet(0);
private Set goodsinfos_1 = new HashSet(0);
// Constructors /** default constructor */
public Userinfo() {
} /** minimal constructor */
public Userinfo(String userId, String userName, String userPass, String userEmail) {
this.userId = userId;
this.userName = userName;
this.userPass = userPass;
this.userEmail = userEmail;
}
/** full constructor */
public Userinfo(String userId, String userName, String userPass, String userEmail, String userIntro, String userAddress, String userPicture, Date userBirth, Boolean userIsActive, Integer userPower, Set useractives, Set userfondinfos, Set useractives_1, Set goodsinfos, Set userfondinfos_1, Set goodsinfos_1) {
this.userId = userId;
this.userName = userName;
this.userPass = userPass;
this.userEmail = userEmail;
this.userIntro = userIntro;
this.userAddress = userAddress;
this.userPicture = userPicture;
this.userBirth = userBirth;
this.userIsActive = userIsActive;
this.userPower = userPower;
this.useractives = useractives;
this.userfondinfos = userfondinfos;
this.useractives_1 = useractives_1;
this.goodsinfos = goodsinfos;
this.userfondinfos_1 = userfondinfos_1;
this.goodsinfos_1 = goodsinfos_1;
}
// Property accessors public String getUserId() {
return this.userId;
}
public void setUserId(String userId) {
this.userId = userId;
} public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
} public String getUserPass() {
return this.userPass;
}
public void setUserPass(String userPass) {
this.userPass = userPass;
} public String getUserEmail() {
return this.userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
} public String getUserIntro() {
return this.userIntro;
}
public void setUserIntro(String userIntro) {
this.userIntro = userIntro;
} public String getUserAddress() {
return this.userAddress;
}
public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
} public String getUserPicture() {
return this.userPicture;
}
public void setUserPicture(String userPicture) {
this.userPicture = userPicture;
} public Date getUserBirth() {
return this.userBirth;
}
public void setUserBirth(Date userBirth) {
this.userBirth = userBirth;
} public Boolean getUserIsActive() {
return this.userIsActive;
}
public void setUserIsActive(Boolean userIsActive) {
this.userIsActive = userIsActive;
} public Integer getUserPower() {
return this.userPower;
}
public void setUserPower(Integer userPower) {
this.userPower = userPower;
} public Set getUseractives() {
return this.useractives;
}
public void setUseractives(Set useractives) {
this.useractives = useractives;
} public Set getUserfondinfos() {
return this.userfondinfos;
}
public void setUserfondinfos(Set userfondinfos) {
this.userfondinfos = userfondinfos;
} public Set getUseractives_1() {
return this.useractives_1;
}
public void setUseractives_1(Set useractives_1) {
this.useractives_1 = useractives_1;
} public Set getGoodsinfos() {
return this.goodsinfos;
}
public void setGoodsinfos(Set goodsinfos) {
this.goodsinfos = goodsinfos;
} public Set getUserfondinfos_1() {
return this.userfondinfos_1;
}
public void setUserfondinfos_1(Set userfondinfos_1) {
this.userfondinfos_1 = userfondinfos_1;
} public Set getGoodsinfos_1() {
return this.goodsinfos_1;
}
public void setGoodsinfos_1(Set goodsinfos_1) {
this.goodsinfos_1 = goodsinfos_1;
}}