Dear Spring Community,
I am a new bee to Spring framework please bear with me and also if Admins think that this thread is not suitable for this part of forum, please feel free to forward to the right place.
If there are some sentences that does not make sense please feel free to correct those , so I can learn too.
My objective is to make a DB connection so that I can test UI vs Database.
Below is the my architecture
architecture.jpg
As you can see , I have config folder that hosts the bean.xml
Here is the bean.xml
---------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schem...ng-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schem...ontext-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:annotation-config/>
<!-- read properties file -->
<contextroperty-placeholder location="classpath:Selenium2Minted/src/util/qa-datasource.properties,
classpath:Selenium2Minted/src/util/database.properties"/>
<!-- Staging data source -->
<tx:annotation-driven proxy-target-class="true"
transaction-manager="mintedTransactionManager"/>
<bean id="mnpTransactionManager"
class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
<property name="dataSource" ref="mintedDataSource"/>
</bean>
<bean id="mintedDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<description>
Connection pool to a staging data source.
</description>
<property name="driverClass" value="${minted.driver.class.name}"/>
<property name="jdbcUrl" value="${minted.url}" />
<property name="user" value="${minted.username}" />
<property name="password" value="${minted.password}"/>
<property name="acquireIncrement" value="${c3p0.acquire.increment}"/>
<property name="initialPoolSize" value="${c3p0.initial.pool.size}"/>
<property name="maxPoolSize" value="${c3p0.max.pool.size}"/>
<property name="maxIdleTime" value="${c3p0.max.idle.time}"/>
<property name="minPoolSize" value="${c3p0.min.pool.size}"/>
<property name="maxIdleTimeExcessConnections" value="${c3p0.max.idle.time.excess.connections}"/>
<property name="idleConnectionTestPeriod" value="${c3p0.idle.connection.test.period}"/>
<property name="testConnectionOnCheckin" value="${c3p0.test.connection.on.checkin}"/>
<property name="breakAfterAcquireFailure" value="${c3p0.break.after.acquire.failure}"/>
</bean>
<!-- Staging event data source -->
<tx:annotation-driven proxy-target-class="true"
transaction-manager="mintedTransactionManager"/>
</beans>
---------------------------------------------------------------------------------------------------------------
I also have DatabaseConnection class
---------------------------------------------------------------------------------------------------------------
public class DatabaseConnection {
private Logger logger = Logger.getLogger("DatabaseConnection.class");
private DataSource mintedDataSource;
private ApplicationContext context;
public DatabaseConnection() throws Exception {
String cur_dir = new java.io.File( "." ).getCanonicalPath();
System.out.println(cur_dir);
//String beanXml = "classpath:../resources/qa-automation.xml";
context = new ClassPathXmlApplicationContext("src/config/qa-automation.xml");
mintedDataSource = (DataSource)context.getBean("mintedDataSource");
}
---------------------------------------------------------------------------------------------------------------
When I run the test cases . Here is the stack trace that I got.
--------------------------------------------------------------------------------------------------------------
[TestNG] Running:
C:\Users\Murat\AppData\Local\Temp\testng-eclipse--597535218\testng-customsuite.xml
FF is selected
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientC onnManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
C:\Users\Murat\workspaceold2\Selenium2Minted
FAILED CONFIGURATION: @BeforeMethod setUp("ff")
org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [src/config/qa-automation.xml]; nested exception is java.io.FileNotFoundException: class path resource [src/config/qa-automation.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:302)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:174)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:209)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:180)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:127)
at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:93)
at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:522)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:436)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
at util.DatabaseConnection.<init>(DatabaseConnection. java:27)
at com.minted.SeleniumTestCase.initDataSources(Seleni umTestCase.java:66)
at com.minted.SeleniumTestCase.setUp(SeleniumTestCase .java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:33 4)
at org.testng.SuiteRunner.runSequentially(SuiteRunner .java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java :291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerW orker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker .java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.jav a:1170)
at org.testng.TestNG.runSuitesLocally(TestNG.java:109 5)
at org.testng.TestNG.run(TestNG.java:1007)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.ja va:109)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTe stNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.j ava:173)
Caused by: java.io.FileNotFoundException: class path resource [src/config/qa-automation.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getI nputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:328)-------------------------------------------------------------------------------------------------------------After searching long times on the net.
Here is what I had tried so far with no luck.
1.Add the config folder to the classpath in Eclispe.
If you can help with this , it will be greatly appreciated.


roperty-placeholder location="classpath:Selenium2Minted/src/util/qa-datasource.properties,
Reply With Quote