Announcement Announcement Module
Collapse
No announcement yet.
Specifying autowire mode for dependency injection in tests Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Specifying autowire mode for dependency injection in tests

    Hi,

    The default auto wiring mode for unit tests in the 'mock' module is autowire by type. I'd like to change this to autowire by name. How can I achieve this? I tried to use the setAutowireMode method, but oddly enough its not even visible in my unit test. Has anyone tried to do this before ?

    Herez what my unit test looks like
    Code:
    public class TransactionalTest extends AbstractTransactionalSpringContextTests  {
     ....
     	public TransactionalTest() {
    		super();
    //Next line causes a compiler error!
    	 setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
    	} 
    }
    The method signature of the API that I'm trying to use is

    Code:
    public abstract class AbstractDependencyInjectionSpringContextTests ... {
     ...
    	/**
    	 * Set the autowire mode for test properties set by Dependency Injection.
    	 * <p>The default is "AUTOWIRE_BY_TYPE". Can be set to "AUTOWIRE_BY_NAME"
    	 * or "AUTOWIRE_NO" instead.
    	 * @see #AUTOWIRE_BY_TYPE
    	 * @see #AUTOWIRE_BY_NAME
    	 * @see #AUTOWIRE_NO
    	 */
    	public final void setAutowireMode(int autowireMode)      {
    		this.autowireMode = autowireMode;
    	}
    ...
    }
    And this should be accessible. I can't make sense of this. Am I missing something?

    Thanks,
    Radhakrishnan

  • #2
    This is weird... your code should work.
    //Next line causes a compiler error!
    setAutowireMode(AutowireCapableBeanFactory.AUTOWIR E_BY_NAME);
    What is the compiler error ?

    Comment


    • #3
      You can have a look at my code here :
      http://tudu.svn.sourceforge.net/view...02&view=markup

      It's AUTOWIRE_NO, but not AUTOWIRE_BY_NAME, but this should not make a big difference and it should help you make your code work.

      I'm also interested by the compiler error you get.

      Comment

      Working...
      X