Detailed explanation of three injection methods of spring bean
•
Java
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
二维码