Detailed explanation of three injection methods of spring bean

There are three ways to configure dependency injection for a bean in the spring container:

Field injection is the most common method. You can use @ Autowired to initialize the interface of bean class. The code is as follows

@ContextConfiguration({"/Meta-INF/spring/amazing-base.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringInjectionTest {
  @Autowired
  private Cust normalCust;
  
  @Test
  public void testFieldInjection() {
    System.out.println("testFieldInjection begin");
    normalCust.recharge();
    System.out.println("testFieldInjection end");
  }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>