1、spring.factories
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.imooc.diveinspringbootzhujie.configuration.HelloWorldAutoConfiguration
2、引导类
package com.imooc.diveinspringbootzhujie.configuration;
import com.imooc.diveinspringbootzhujie.anotation.EnableHelloWorld;
import com.imooc.diveinspringbootzhujie.bootstrap.EnableHelloWorldBootstrap;
import com.imooc.diveinspringbootzhujie.condition.ConditionalOnSystemProperty;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
/*
* HelloWorld自动装配
* */
@Configuration //spring模式注解
@EnableHelloWorld //模块注解
@ConditionalOnSystemProperty(name = "user.name" , value = "Administrator") //条件装配
public class HelloWorldAutoConfiguration {
public static void main(String[] args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder(HelloWorldAutoConfiguration.class)
.web(WebApplicationType.NONE)
.run(args);
String helloWorld = context.getBean("helloWorld", String.class);
System.out.println("hello world bean : " + helloWorld);
}
}