Announcement Announcement Module
Collapse
No announcement yet.
How to programmaticly set spring autowired properties without Spring config? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to programmaticly set spring autowired properties without Spring config?

    How to programmaticly set spring autowired properties without using setter and Spring config?

    I have a interface

    Code:
    public interface MyService {
    ..
    }
    and implementing class

    Code:
    public class MyServiceImpl implements MyService {
    	..
    	@Autowiring
    	private MyDao myDao;
    	..
    }
    In unit test I would like to mock MyDao and set that to MyServiceImpl without making setter method to MyServiceImpl.

    Code:
    public class MyServiceTest {
    	..
    	@Test
    	public void doTest() {
    		MyService myService = new MyServiceImpl();
    		MyDao myDaoMock = Mockito.mock(MyDao.class);
    		..
    		
    		// How to wire myDaoMock to myService without making setMyDao(..) method for MyServiceImpl
    	}
    	..
    }
    How to do it?

  • #2
    hi,

    I've checked Java-based configuraiton, and I couldn't do that neither via @Configuraiton neither via AnnotationConfigApplicationContext method

    Then I've seen this

    look this http://static.springsource.org/sprin...x/javadoc-api/

    "Deprecated. as of Spring 3.0: If you are using mixed autowiring strategies, prefer annotation-based autowiring for clearer demarcation of autowiring needs."

    I guess there's no possiblity you've asked

    Comment


    • #3
      Answering for me:

      http://static.springsource.org/sprin...TestUtils.html

      Comment

      Working...
      X