测试报错与ssm整合中的500

标题

添加@Resource后。No beans of ‘IUserService’ type found。。这个问题捏 就是在spring-mybatis.xml中加个注解。。。
impl包应在service中,以便扫描

<context:component-scan base-package="com.qfedu.service" />

错误日志

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.qfesu.test.TestService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qfedu.service.IUserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

org.springframework.beans.factory.BeanCreationException:创建名为“com.qfesu.test.TestService”的bean时出错:资源依赖项注入失败;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有’com.qfedu.service.IUserService’类型的限定bean可用:至少需要一个符合autowire候选条件的bean。依赖项批注:{@javax.annotation.Resource(shareable=true,lookup=,name=,description=,authenticationType=CONTAINER,type=class java.lang.Object,mappedName=)}

3.测试代码

package com.qfesu.test;

import com.qfedu.pojo.User;
import com.qfedu.service.IUserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.List;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-mybatis.xml")
public class TestService {


    @Autowired
    private IUserService userService;
@Test
    public void testGetAllUser(){
        List<User> list = userService.getAllUsers();
    for (User user : list) {
        System.out.println(user);
    }



    }
}

是因为植入依赖失败 没有关于srervice包的扫描,在spring-mybatis.xml 也要写
最好在spring-mvc 与mybatis中都写 ,这样页面与测试就不会报错了。
现在就OK了!!

HTTP Status 500 - Servlet.init() for servlet springmvc threw exception

这个问题也被我解决了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值