0

How to configure the DataSource tag in the Spring-Server.xml ? I have been trying to configure it, but actually i didn't find any useful reference about that : i was writing it this how :

 <data-source class="org.apache.james.util.dbcp.JdbcDataSource" name="JamesDS">
 <driver>oracle.jdbc.driver.OracleDriver</driver>
 <dburl>jdbc:oracle:thin:@localhost:1522:test</dburl>
 <user>James</user>
 <password>123456</password>
 </data-source>
primeFaceUser
  • 295
  • 2
  • 15

1 Answers1

0

You should configure dataSource as a bean, each line you wrote inside should be defined as a property. An example:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/myschema" />
    <property name="username" value="root" />
    <property name="password" value="password" />
</bean>

As you can see from the example, you can use different drivers - depends on the DB you're connecting to.

Another example:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/myschema" />
    <property name="username" value="root" />
    <property name="password" value="password" />
</bean>

IMPORTANT:
from Spring docs about DriverManagerDataSource:

This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

If you need a "real" connection pool outside of a J2EE container, consider Apache's Jakarta Commons DBCP or C3P0. Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full connection pool beans, supporting the same basic properties as this class plus specific settings (such as minimal/maximal pool size etc).

I recommend on reading the following good introduction to JDBC

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
  • Thank u for your reply! but I am still facing some problems while attempting to start the server(running run.bat) An exception is being thrown java.lang.IllegalStateException : cannot convert value of type [java.lang.String] to required type [org.springframework.orm.jpa.vendor.Database] for property 'database' This exception is thrown because i have written in the Spring-server.xml : under the id=vendorAdapter What do you advice me to do to solve this error – primeFaceUser Aug 21 '13 at 16:36
  • Restarting the server (usually) has nothing to do with DB connection. You should be able to restart the server, and fail on a request to your application that requires DB connection. – Nir Alfasi Aug 21 '13 at 16:37
  • Before editing the datasource configuration, the server starts normally without any exception, but when i configured it, i am sure that i have some mistakes in the configuration, would you please give me a complete sample a\concerning only the datasource block... Thank a lot you in advance !! – primeFaceUser Aug 21 '13 at 17:07
  • @primeFaceUser I posted two examples using different drivers – Nir Alfasi Aug 21 '13 at 17:44