Spring gets Bean directly

1. Append the definition in applicationContext.xml

 

<bean id="testService" class="test.TestService" />

 

 

2. Obtained in Java code

 

WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
TestService testBean = (TestService)wac.getBean("testService")

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326779942&siteId=291194637