项目经验之springmvc单元测试
来源:互联网 发布:文职将军知乎 编辑:程序博客网 时间:2024/05/29 02:24
在SpringMVC的单元测试中,首先要对当前环境进行引入,比如:
@WebAppConfiguration@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes = {NoticeServiceConfig.class})
错误情况:在NoticeServiceConfig类中如下:
@ComponentScan({"com.xx.xx.notice"})@EnableJpaRepositories( basePackages = {"com.xx.xx.common.repository"})@ImportResource("classpath:datasource_mysql.xml")报错:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xx.xx.notice.repository.WeixinSenderRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}究其原因是因为我的dao层接口实现了JpaRepository接口,如果在单元测试中,就必须要引入该dao层所在的package,通过@EnableJpaRepositories指定到相应的包就可以,重点在于使用该注解,不能与@ComponentScan扫描的包的路劲重合,否则会提示:Could not autowire. There is more than one bean of 'WeixinSenderRepository' type. Beans:weixinSenderRepository,weixinSenderRepository.
1 0
- 项目经验之springmvc单元测试
- android项目开发之单元测试
- SpringMVC单元测试
- SpringMvc单元测试
- SpringMVC单元测试
- springmvc单元测试
- springmvc项目单元测试出现的java.lang.NoClassDefFoundError
- 【项目经验】iphone之ASIHTTPRequest
- IntelliJ IDEA单元测试+SpringMvc单元测试
- SpringMVC异步处理之@Async(附源代码 - 单元测试通过)
- SpringMVC单元测试之MockMVC,模拟登入用户
- SpringMVC单元测试之MockMVC,模拟登入用户
- 降魔篇之springmvc项目开发
- 单元测试项目
- springmvc controller 单元测试
- SpringMVC Junit单元测试
- springmvc mock单元测试
- Junit对SpringMVC单元测试
- Spring中RedirectAttributes说明
- Django + nginx + uwsgi配置和环境搭建(ubuntu)
- JSP页面端获取应用的路径
- C# 委托的使用(指向函数的指针)
- $_SERVER只能在apache服务器下使用
- 项目经验之springmvc单元测试
- undo表空间概述
- Andriod更换背景颜色
- C# 反射
- 网页优化
- PHP - ArrayAccess接口详解
- 【bzoj3564】 [SHOI2014]信号增幅仪
- 第八道ACM程序题
- iOS Crash收集框架