SpringBoot在test环境中无法注入bean的问题

问题:

说明bean没有注入成功

改为以下格式即可:加上一个注解

package com.qcby.springboot;

import com.qcby.springboot.mapper.PersonMapper;
import com.qcby.springboot.model.TxPerson;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest(classes = {SprigBootDemo10Application.class})
@RunWith(SpringRunner.class)
public class Demo11ApplicationTests {

    @Autowired
    private PersonMapper personMapper;


    @Test
    public void contextLoads() {
        List list = personMapper.getPersons();
        System.out.println(list);
    }


}

你可能感兴趣的:(spring,boot,后端,java)