Spring framework: If I try to use the same class in two otherclasses, a huge loop of loading starts

Discussion in 'Java' started by je.kowalski2013@gmail.com, Aug 14, 2013.

  1. Guest

    @BeforeReadingConsider
    new to java - 4 weeks
    new to spring - 1 day

    @QuestionBody
    I am using Spring framework. I have a TestNG dataprovider class that creates and sets up the Selenium Webdriver objects Driver and Wait. I want to use its attributes in two other classes

    This is the data provider class


    public class DataProviderClass {
    public static WebDriver driver;
    public static WebDriverWait wait;
    public static ArrayList<ArrayList<String>> array;
    final static String FILE_PATH = "src/test/resources/250.csv";

    @DataProvider(name="standardTestData")
    public static Object[][] setUp() throws Exception {

    //prepare variables here


    //pass the data to the test case
    Object[][] setUp = new Object[1][3];
    setUp[0][0] = driver;
    setUp[0][1] = wait;
    setUp[0][2] = array;
    //setUp[0][3] = array2;
    return setUp;
    }

    And in the test class I use some custom made methods that I get from another class
    In the test class I inject the data provider class and the method class like so:

    public class AppTest3 {

    public static DataProviderClass appdata;
    public static WebDriverCustomMethods w;

    public AppTest3 () {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    appdata = (DataProviderClass) context.getBean("data");
    w = (WebDriverCustomMethods) context.getBean("wdcm");
    }

    But the method class doesnt recognise "Driver" and "Wait" objects, so I want to inject the Dataprovider class there as well:

    public class WebDriverCustomMethods{

    public static DataProviderClass appdata;
    public WebDriver driver;
    public WebDriverWait wait;

    public WebDriverCustomMethods () {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    appdata = (DataProviderClass) context.getBean("data");
    }


    //close the firefox instance after testing or on error
    public void quit() {
    driver.quit();
    }

    And when I start the test class, a huge loop of spring loading happens and It stops working at the end:

    //this is only a small part of the console output
    INFO: Loading XML bean definitions from class path resource [spring.xml]
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3586385a: defining beans [data,wdcm,mailer]; root of factory hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7eddb829: startup date [Wed Aug 14 12:40:41 EEST 2013]; root of context hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [spring.xml]
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@376ea355: defining beans [data,wdcm,mailer]; root of factory hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@40a53de1: startup date [Wed Aug 14 12:40:41 EEST 2013]; root of context hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [spring.xml]
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@a440543: defining beans [data,wdcm,mailer]; root of factory hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@77b576f8: startup date [Wed Aug 14 12:40:41 EEST 2013]; root of context hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [spring.xml]
    Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6de1bddb: defining beans [data,wdcm,mailer]; root of factory hierarchy
    Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7f77ad38: startup date [Wed Aug 14 12:40:41 EEST 2013
    , Aug 14, 2013
    #1
    1. Advertising

  2. Joerg Meier Guest

    Re: Spring framework: If I try to use the same class in two other classes, a huge loop of loading starts

    On Wed, 14 Aug 2013 05:17:41 -0700 (PDT), wrote:

    > I am using Spring framework. I have a TestNG dataprovider class that creates and sets up the Selenium Webdriver objects Driver and Wait. I want to use its attributes in two other classes


    I am not at all familiar with Spring, but I have seen this same issue with
    other injection frameworks, and the usual solution is not to use direct
    injection of the needed classes, but to use producers instead, which then
    inject an instance later, when it is first needed. Maybe Spring provides a
    similar mechanism.

    Liebe Gruesse,
    Joerg

    --
    Ich lese meine Emails nicht, replies to Email bleiben also leider
    ungelesen.
    Joerg Meier, Aug 14, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    9,300
    Darryl L. Pierce
    Sep 11, 2005
  2. Replies:
    0
    Views:
    483
  3. rmn190
    Replies:
    2
    Views:
    2,339
    Arne Vajhøj
    Jan 10, 2008
  4. Goldfish
    Replies:
    1
    Views:
    658
    Goldfish
    Nov 6, 2008
  5. Isaac Won
    Replies:
    9
    Views:
    352
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page