Results 1 to 3 of 3

Thread: How to programmaticly set spring autowired properties without Spring config?

  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Default 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. #2
    Join Date
    Feb 2010
    Posts
    7

    Default

    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

  3. #3
    Join Date
    Jan 2010
    Posts
    2

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •