JavaconfigApplicationTests
package com.example.demo;
import com.example.demo.config.JavaConfig;
import com.example.demo.model.Printer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class JavaconfigApplicationTests {
@Test
public void contextLoads() {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(JavaConfig.class);
Printer printer = context.getBean(Printer.class);
printer.print();
context.close();
}
}
package com.example.demo.model;
/**
* Created by Administrator on 2017/12/25.
*/
public class ColorInk {
public void getColor(){
System.out.println("我是红色");
}
}