配置类
package com.springboot.springboot_demo.config;
import com.springboot.springboot_demo.pojo.Dog;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class BeanConfig {
@Bean(name = "dog")
public Dog getDog(){
Dog dog = new Dog();
dog.setAge("21");
dog.setName("哈士奇");
return dog;
}
}
测试方法
@Autowired
@Qualifier("dog")
private Dog dog;
@Test
public void dogTest() {
System.out.println(dog);
}
输出
Dog(name=哈士奇, age=21)