• 解决:ApplicationTest does not declare any static, nonprivate, nonfinal, nested classes annotated with @Configuration


    这是在运行测试类的时候提示报错信息;
    原因是没有把启动类写好或者是没有配置启动类;
    解决如下,
    先是要正常写好启动类;
    然后把启动类添加到运行的测试类,添加到这个地方:@SpringBootTest;
    有两种填写方式,一种是:@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    
    还有一种是网上反馈的方法:
    @SpringBootTest(classes = {启动类.class })//这里加启动类
    
    package com.itheima;
    
    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 com.itheima.domain.Person;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    public class ApplicationTest {
        @Autowired
        private Person person;
    
        @Test
        public void contextLoads() {
            System.out.println(person);
        }
    }
  • 相关阅读:
    go语言的grpc安装记录
    MySQL1:客户端/服务器架构
    设计模式
    乐观锁与悲观锁的选择
    compareAndSwapObject 产生ABD原因
    wangEditor
    ckeditor4学习
    git公司远程提交
    java面试题总结
    基本数据类型和包装类
  • 原文地址:https://www.cnblogs.com/tszr/p/15907151.html
Copyright © 2020-2023  润新知