解決:ApplicationTest does not declare any static, non-private, non-final, 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);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM