Maven项目下整合spring和mybatis后用Junit测试 Failed to load Applic

J2EE 码拜 9年前 (2016-05-14) 1015次浏览
测试的代码:
import static org.junit.Assert.*;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.zw.wei.bean.User;
import com.zw.wei.service.UserService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { “classpath:/spring/spring-mybatis.xml”})
public class TestMybatis {
private static Logger logger = Logger.getLogger(TestMybatis.class);
@Resource
private UserService userService=null;
// @Before
// public void setUp() throws Exception {
// ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
// “spring/applicationContext.xml”);
// userService = (UserService) applicationContext
// .getBean(“userServiceImpl”);
// }
@Test
public void test() {
User user = userService.getUserById(1);
//  System.out.println(user.getUsername());
//  logger.info(“值:”+user.getUsername());
// logger.info(JSON.toJSONString(user));
}
}
运行后报错,代码在回复里
解决方案

10

 java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
缺spring-jdbc的jar包吧

10

“sqlSessionFactory” defined in class path resource [spring/spring-mybatis.xml],它说在你的XML配置文件中没有定义SQLSessionFactory,少JDBC的jar包吧去Spring中找就是了

40

引用:

 java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
缺spring-jdbc的jar包吧

嗯好的,本人看看pom.xml里有没有配置


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Maven项目下整合spring和mybatis后用Junit测试 Failed to load Applic
喜欢 (0)
[1034331897@qq.com]
分享 (0)