Spring @Bean 标签
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| @Bean public TestA testA() { return new TestA(); }
for (int i = 0; i < 5; i++) { System.err.println(testA().toString()); }
@Component public class TestCommder implements CommandLineRunner { @Autowired TestA testA;
@Override public void run(String... arg0) throws Exception { System.err.println("auto wired..." + testA.toString()); }
}
|
A: 你这样反复调用testA()方法会产生很多对象,巴拉巴拉…你这样不对,快改。
B:一脸啊懵逼….
1 2 3 4 5 6 7 8
| 输出结果:
com.igaming.extmail.TestA@407cf41 com.igaming.extmail.TestA@407cf41 com.igaming.extmail.TestA@407cf41 com.igaming.extmail.TestA@407cf41 com.igaming.extmail.TestA@407cf41 auto wired...com.igaming.extmail.TestA@407cf41
|
老子说:夫为不争,故无忧。博君一笑!!!