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")