Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: @ContextConfiguration

  1. #11
    Join Date
    Jan 2006
    Location
    Zürich, Switzerland
    Posts
    423

    Default

    Hi Sudhcha,

    FYI: your configuration is overkill. You should practically never need to implement ApplicationContextAware in a test class. Instead, you should just autowire your test dependencies -- you should not look them up manually via ApplicationContext.getBean(...).

    In addition, @Configurable has no place in a test class!

    Thus, your example should be rewritten as follows (for Spring 3.0+):

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("/com/emc/config/spring.cfg.xml")
    public class HelloServiceTest {
    
    	@Autowired
    	private HelloService helloService;
    	
    	@Test
    	public void testHello() {
    		helloService.sayHello("Tom");
    	}
    }
    Cheers,

    Sam

  2. #12
    Join Date
    Nov 2007
    Posts
    25

    Default Proposed Spring Enhancement

    In order to address this issue, I have created https://jira.springsource.org/browse/SPR-9044. If you like the proposed approach, please vote for it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •