Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Spring framework: If I try to use the same class in two otherclasses, a huge loop of loading starts

Reply
Thread Tools

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

 
 
je.kowalski2013@gmail.com
Guest
Posts: n/a
 
      08-14-2013
@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.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@3586385a: defining beans [data,wdcm,mailer]; root of factory hierarchy
Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@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.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@376ea355: defining beans [data,wdcm,mailer]; root of factory hierarchy
Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@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.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@a440543: defining beans [data,wdcm,mailer]; root of factory hierarchy
Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@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.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Aug 14, 2013 12:40:41 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@6de1bddb: defining beans [data,wdcm,mailer]; root of factory hierarchy
Aug 14, 2013 12:40:41 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@7f77ad38: startup date [Wed Aug 14 12:40:41 EEST 2013


 
Reply With Quote
 
 
 
 
Joerg Meier
Guest
Posts: n/a
 
      08-14-2013
On Wed, 14 Aug 2013 05:17:41 -0700 (PDT), http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are class static functions not in the scope of the class? Shriramana Sharma C++ 4 05-05-2013 12:57 PM
How to capture the “same” RGB images for the same scene using EDSDK? azuring@gmail.com Digital Photography 0 04-28-2013 12:08 PM
The node.js Community is Quietly Changing the Face of Open Source Rodrick Brown Python 2 04-17-2013 04:47 PM
Is there a difference between the use of the word montage vscollage Danny D. Digital Photography 8 04-15-2013 02:24 PM
Windows 8 - so bad it's hastening the death of the PC? ~misfit~ NZ Computing 18 04-15-2013 04:15 AM



Advertisments