一、创建HelloService
二、创建配置类
测试容器中是否包含helloService类
package com.laoxu.springboot;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
@SpringBootTest()
class SpringBoot02ConfigApplicationTests {
@Autowired
ApplicationContext ioc;
@Test
void contextLoads() {
}
@Test
public void testhelloservice(){
boolean b = ioc.containsBean("helloService");
System.out.println(b);
}
}
bean的名字为@Bean注解下的方法名