I am working on a Spring project where the unit tests have their own config called UnitTestConfig which has several beans defined similar to the main application file (almost a replica). Keeping the structure intact, i am making some changes in main application server code, however this throws error in UnitTestConfig, because it doesnt have the required beans for injection. These beans are not used in Unit tests, is there a way I can prevent UnitTestConfig from trying to inject those? Its a big casacade effect, since A injects, B injects C, and so on, and it is expecting all those Beans. Any way I can tell Spring config that i dont want to inject those beans or have them as null ?
@Configuration
public class UnitTestConfig {
@Inject
private Environment env;
@Bean
public A a() {
return new A();
}
In order to not inject A's fields when required, i added a @Lazy over the field and it seemed to work, but I would prefer any modifications for this to be on the test config side, and not modify main application code just to fix test issues. Any suggestions?