user620339
user620339

Reputation: 901

getting the context object after setting it using @ContextConfiguration

How do I get ApplicationContext object so that i can use it in my code, after setting context using@ContextConfiguration.

My test class extends AbstractTransactionalJUnit4SpringContextTests.

Upvotes: 4

Views: 4481

Answers (2)

Karthik Ramachandran
Karthik Ramachandran

Reputation: 12175

I generaly just inject a copy of the Application Context into the unit test:

 @Autowired 
   ApplicationContext context;

Upvotes: 10

skaffman
skaffman

Reputation: 403441

AbstractTransactionalJUnit4SpringContextTests extends AbstractJUnit4SpringContextTests, which has a protected applicationContext field. Your test class can just use that.

Upvotes: 5

Related Questions