I would use the Spring @Profile function, which I assume is the "environment" that you talked about.
For instance:
@Service @Profile("dev") public class FakeWebService implements WebService { } @Service @Profile("production") public class ExternalWebService implements WebService { }
EDIT
And indicate which profile to use in your test:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/app-config.xml") @ActiveProfiles("dev") public class MyAcceptanceTest { }
See this section of the Spring docs for more details.
There are several ways to set an active profile during production, but the method I used earlier is in the web.xml file:
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>spring.profiles.active</param-name> <param-value>production</param-value> </init-param> </servlet>
source share