import com.bdqn.lyrk.springboot.study.pojo.Student;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
Student student = applicationContext.getBean(Student.class);
System.out.println(student.getLoginName());
}
}
当运行成功时:我们可以看到输出Student的loginName属性是test
6.在META-INF/spring.factories编写如下代码:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.bdqn.lyrk.springboot.study.configuration.MyTestAutoConfiguration
注意:此配置文件非常重要,当我们这个jar包被SpringBoot依赖时,spring会读取org.springframework.boot.autoconfigure.EnableAutoConfiguration所定义的配置类并加载