I have the following configuration bean for a non web app
@Configuration
public class MyBeans {
@Bean
@Scope(value="prototype")
MyObject myObject() {
return new MyObjectImpl();
}
}
On the other side I have my class
public class MyCommand implements Command {
@Autowired
private MyObject myObject;
[...]
}
How can I make myCommand be autowired with the configuration in MyBeans without using XML so I can inject mocks in my other test classes?
Thanks a lot in advance.
With XML-based configuration you’d use the ContextConfiguration annotation. However, the ContextConfiguration annotation doesn’t appear to work with Java Config. That means that you have to fall back on configuring your application context in the test initialization.
Assuming JUnit4: