Get Spring AppCtx outside web context & w/o Spring

Discussions

General J2EE: Get Spring AppCtx outside web context & w/o Spring

  1. Get Spring AppCtx outside web context & w/o Spring (1 messages)

    Has anyone ever found cause to obtain a Spring app context from a static class method with a ThreadLocal so that it could be obtained by objects that aren't managed via Spring and aren't in a web context? Anyone armed with reasons against such an approach? I can think of one or two possible reasons against doing this myself, but they might not be enough to stop me. Just curious...

    Thanks
  2. Check out AbstractTransactionalDataSourceSpringContextTests
    if your trying to unit test.


    otherwise..

    ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"/daoContext.xml","/datasource-junit.xml"});
    IUserDAO userDAO = (IUserDAO)context.getBean("userDAO");