Entity class:
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Pat {
private String name;
private Integer age;
}
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class User {
private String name;
private Integer age;
private Pat pat;
public User(String name, Integer age) {
this.name = name;
this.age = age;
}
}
Annotation description:
@Import({User.class, DBHelper.class}): These two types of components are automatically created in the container, and the default component name is the full class name
Output component information in the startup class:
/**
* com.itcast.bean.User: @Import导入的
* user01:bean注解导入
*/
for (String s : beanNamesForType) {
System.out.println(s);
}
System.out.println("==============");
String[] dbhelper = run.getBeanNamesForType(DBHelper.class);
for (String s : dbhelper) {
System.out.println(s);
}
System.out.println("==============");
String[] pat = run.getBeanNamesForType(Pat.class);
for (String s : pat) {
System.out.println(s);
}
Console output information:
==============
com.itcast.bean.User: @Import注解输出
user01 @Bean注解输出
==============
ch.qos.logback.core.db.DBHelper
==============
jiangziya
Lei Fengyang 2021 version of SpringBoot2 zero-based entry springboot full set of full version (spring boot2)