使用spring 集成测试时报错
这个是错误信息(测试模式)org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcr...
这个是错误信息(测试模式)org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'test.UserTest': Unsatisfied dependency expressed through bean property 'userService': Set this property value or disable dependency checking for this bean.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1019)
这个是测试类(UserTest)
package test;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import service.UserService;
public class UserTest extends AbstractDependencyInjectionSpringContextTests{
private UserService userService;
public void setUserService(UserService userService) {
this.userService = userService;
}
protected String[] getConfigLocations() {
return new String[] { "applicationContext.xml" };
}
public void testSaveUser(){
assertTrue(userService.allUser());
}
}
配置文件:applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans /**头文件,字数太多,省略">
<bean id="dataSource"
/**节省字数,建立连接省略,用的是mysql*/
</bean>
<bean id="sessionFactory"
/**建立sessionFactory配置,*/
</bean>
<bean id="userDao" class="dao.UserDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userService" class="service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
</beans> 展开
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:1019)
这个是测试类(UserTest)
package test;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import service.UserService;
public class UserTest extends AbstractDependencyInjectionSpringContextTests{
private UserService userService;
public void setUserService(UserService userService) {
this.userService = userService;
}
protected String[] getConfigLocations() {
return new String[] { "applicationContext.xml" };
}
public void testSaveUser(){
assertTrue(userService.allUser());
}
}
配置文件:applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans /**头文件,字数太多,省略">
<bean id="dataSource"
/**节省字数,建立连接省略,用的是mysql*/
</bean>
<bean id="sessionFactory"
/**建立sessionFactory配置,*/
</bean>
<bean id="userDao" class="dao.UserDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userService" class="service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
</beans> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询