This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Overriding beans for testing

Aug 16th, 2005, 01:42 PM

Hi. I am trying to set up an integration test, so I want to load all of my contexts. One of them is for a DataSource and uses the JndiObjectFactoryBean. If I try to load this in a JUnit test, I get an error about not specifying a class name for the InitialContext.

If I could get the production context to load, then I could load the testing context and supply the production context as a parent and it would work fine, but of course, I cannot get the production context to load.

How can I override this one definition? Should I move the single definition into its own file, then create a testing-context.xml. This way I could load the production-context.xml in production and the testing-context.xml in testing. I do not really like this idea because there could be more definitions I want to override. I like the organization I currently have and I do not want to move the dataSource definition out of the logically grouped context I have. If I later need to override some of the email settings (which I foresee), I do not want to pull a server defintion out of the email-context.xml and into a production-context.xml. I would prefer to keep those definitions logically grouped.