我有一个Spring应用程序和与此应用程序相关的集成测试。我想用模拟bean替换一个bean。
我的真实bean长这样:
@Service
public class MyService {
}
并且为了测试,我希望它被替换掉
@Service
public class TestMyService {
}
我所能想到的是为不同的服务使用不同的配置文件。例如:
@Service
@Profile("!test")
public class MyService implements IMyService {
}
@Service
@Profile("test")
public class TestMyService implements IMyService {
}
然后我像这样自动装配bean
@Autowired
private IMyService myService;
有更好的方法吗?