使用注解配置Bean

  作者:记性不好的阁主

一、创建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注解下的方法名







相关推荐

评论 抢沙发

表情

分类选择