Reputation: 358
I have code that can be run properly as a JUnit test case. However, when I put the same test code inside a main class, spring configuration do not properly load the objects.
Spring code looks like this:
@ContextConfiguration(locations = { "classpath:/fileonly-sens-services.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class AppTest extends ContextBuilder {
@BeforeClass
public static void setup() {
System.setProperty("app-
init.properties","classpath:test.app.properties");
@Test
someTestMethod()
}
I think it is a very simple problem but I cannot get it working outside of JUnit! Thanks for the help!
Upvotes: 0
Views: 60
Reputation: 6289
In your application you will have to create an ApplicationContext. The specifics of how to do it, depends on what kind of application you are building.
If you are building a command-line application, you can instantiate ClassPathXmlApplicationContext and use it to instantiate needed beans.
If you are building a web application, you can use ContextLoaderListener to load context during your application initialization.
Upvotes: 1