You should check the mission statements of Spring:
Your application code should ''not'' depend on Spring APIs
If you add a BeanFactory/ApplicationContext to your beans, you are violating the mission statement 
You don`t want your pojo`s to have a reference of any kind to a Spring object. Your pojo`s are created in the application context, but all objects they require can be injected (via constructor or via a setter) in these beans, eg:
Code:
interface LoggingService{
void log(String s);
}
class LogginServiceImpl implements LoggingService{
void log(String s){... do something ... }
}
interface FooDao{
void deleteAllSillyObjects();
}
class FooDaoImpl implements FooDao{
void deleteAllSillyObjects(){... delete those bastards ..}
}
class FooService{
private FooDao fooDao;
private LoggingService loggingService;
FooService(FooDao fooDao, LogginService loggingService){
this.fooDao = fooDao;
this.loggingService = logginService;
}
void sillyMethod1(){
loggingService.log("silly method1");
}
void sillyMethod2(){
fooDao.deleteAllSillyObjects();
}
}
And this would be your application context:
Code:
<bean id="loggingService" class="LoggingServiceImpl"/>
<bean id="fooDao" class="FooDaoImpl"/>
<bean id="fooService" class="FooService">
<constructor-arg>
<ref bean="fooDao"/>
</constructor-arg>
<constructor-arg>
<ref bean="loggingService"/>
</constructor-arg>
</bean>
Now your fooService is created. He received his arguments via a constructor and he realy doesn`t care how he is created. This is the easiest way to set up your beans. As far as your beans are concerned, Spring doesn`t exist.. and that is great because it will make your code more reusable, better testable and not dependant on Spring.
For a test setup you could create your beans the classic way:
Code:
LoggingService loggingService = new MockLoggingService();
FooDao fooDao = new MockFooDao();
FooService fooService = new FooService(fooDao,loggingService)
If you understand this part of Spring you will see that a new role is emerging: the component configurator/system glue-er. It`s like playing with Lego.. just just fit all the peaces together (maybe creating new ones if one is needed). And the best thing is... you always have enough bricks