Results 1 to 2 of 2
  1. #1
    springlover is offline Member
    Join Date
    Jun 2014
    Posts
    1
    Rep Power
    0

    Default Using BasicDataSourceFactory

    I want to have a factory class (and create a bean for it in my XML file) which will return a BasicDataSource object any time the factory class is referenced in my XML file. Below is an example of what I mean:

    ApplicationContext.xml
    Java Code:
    <?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:context="http://www.springframework.org/schema/context"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    
    	<bean id="factory" class="org.apache.commons.dbcp.BasicDataSourceFactory" />
    
    	<bean id="DataSourceUserBean" class="DataSourceUser">
    		<property name="source" ref="factory" />
    	</bean>
    
    </beans>
    DataSourceUser.java
    Java Code:
    public class DataSourceUser 
    {
    
    	private BasicDataSource source;
    
    	public BasicDataSource getSource() 
    	{
    		return source;
    	}
    
    	public void setSource(BasicDataSource source) 
    	{
    		this.source = source;
    	}
    	
    }
    Main.java
    Java Code:
    public static void main(String[] args) 
    {
    	ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
    }
    When I run my program I get this error: Cannot convert value of type [org.apache.commons.dbcp.BasicDataSourceFactory] to required type [org.apache.commons.dbcp.BasicDataSource] for property 'source': no matching editors or conversion strategy found

    What am I doing wrong? Obviously I'm using the BasicDataSourceFactory incorrectly -- can someone show me what exactly I'm doing wrong?

  2. #2
    Join Date
    Apr 2014
    Posts
    41
    Rep Power
    0

    Default Re: Using BasicDataSourceFactory

    you can do following

    in tomcat7/conf/context.xml just add factory="org.apache.tomcat.jdbc.pool.DataSourceFac tory"

    So context.xml looks like the following

    <Context>
    <Resource name="..." auth=".."
    type="..."
    driverClassName="..."
    url="..."
    username="..."
    password="..." maxActive="20" maxIdle="10"
    factory="org.apache.tomcat.jdbc.pool.DataSourceFac tory"
    maxWait="-1"/>
    </Context>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •