spring - Integration test: test the Autowired annotation -
i want test injection dependencies in spring.
i have class:
public someclass { @autowired somebean bean ; public somebean getbean(){ return this.bean ; } }
i want test this:
public someclasstest { someclass someclass ; @before public void setup(){ someclass = new someclass() ; } @test public testbeanwired(){ assertnotnull(someclass.getbean()) ; } }
i have tried contextconfiguration test configuration file, test fails, don't want use @autowired in test, want create instance of class , bean autowired automatically.
that possible if bean annotated @configuration , if byte-code instrumented. otherwise, beans created spring autowired. not beans created using new
. because spring has no way know created object , must inject dependency in it.
that's fundamental principle of dependency injection: objects instantiated , injected container, not you.
Comments
Post a Comment