문제

I have a test case where I have an @Autowired Foo foo which I need to have injected just once, so all the test methods could re-use the same data foo has. What is currently happening is that upon every @Test method's invocation, the foo bean is cleanly re-loaded by Spring.

Is is possible to load this bean just once for the whole test class and how is it done?

도움이 되었습니까?

해결책

This behavior is probably environment specific since they differ in the loading of the Spring context. For example, Eclipse does not automatically reload the context between tests but Maven does.

I would suggest that you write a @Before method that copies the @Autowired reference into another field and have your tests use that field.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top