Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24972 > unrolled thread

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

Started byje.kowalski2013@gmail.com
First post2013-08-14 05:17 -0700
Last post2013-08-14 19:47 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Spring framework: If I try to use the same class in two other classes, a huge loop of loading starts je.kowalski2013@gmail.com - 2013-08-14 05:17 -0700
    Re: Spring framework: If I try to use the same class in two other classes, a huge loop of loading starts Joerg Meier <joergmmeier@arcor.de> - 2013-08-14 19:47 +0200

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

Fromje.kowalski2013@gmail.com
Date2013-08-14 05:17 -0700
SubjectSpring framework: If I try to use the same class in two other classes, a huge loop of loading starts
Message-ID<a7dedfa6-0543-4653-8c2b-c87e217ae1e3@googlegroups.com>
@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

[toc] | [next] | [standalone]


#24977

FromJoerg Meier <joergmmeier@arcor.de>
Date2013-08-14 19:47 +0200
Message-ID<1jg35mjjbur0y$.m6r5geeo6f74.dlg@40tude.net>
In reply to#24972
On Wed, 14 Aug 2013 05:17:41 -0700 (PDT), je.kowalski2013@gmail.com 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web