Reputation: 1
I have extended the BasicDataSourceFactory (of [Apache Commons] DBCP) as follows:
public class MyFactory extends BasicDataSourceFactory {
public MyFactory () {}
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws SQLException {
return super.getObjectInstance(obj, name, nameCtx, environment);
}
}
I'm using this class as factory in my Resources's definition in the context.xml:
<Resource name="MyResource"
auth="Container"
type="javax.sql.DataSource"
factory="path.to.my.factory.MyFactory"
username="myusername"
password="mypassword"
driverClassName="oracle.jdbc.OracleDriver"
url="myUrl"
maxTotal="8"
maxIdle="4"
defaultAutoCommit="true"
removeAbandonedOnBorrow="true"
removeAbandonedOnMaintenance="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1 FROM DUAL">
</Resource>
Then I try to retrieve MyResource:
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("MyResource");
ds.getConnection().setAutoCommit(false);
The DataSource seems to create ok, because ds has all the properties defined in the context.xml (user, password, url, driver...). BUT when I call getConnection, I get the ORA-28040 error.
HOWEVER, if I remove the line factory="path.to.my.factory.MyFactory"
from the DataSource resource's definition (I assume it will use a generic factory), getConnection works fine. What am I missing?
I'm using ojdbc8/JDK8 with an Oracle 19 database, which are supposed to be compatible, according to Oracle documentation.
I've tried with a couple of the latest versions of ojdbc8, so my pom.xml will look like:
<!-- mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>23.5.0.24.07</version>
</dependency>
Or:
<!-- mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>23.2.0.0</version>
</dependency>
I'm using Apache Tomcat 8.5.76.
Upvotes: 0
Views: 97
Reputation: 1
I finally found out the solution by myself. The problem was that I had to extend BasicDataSourceFactory from org.apache.tomcat.dbcp.dbcp2 instead of extending BasicDataSourceFactory from org.apache.commons.dbcp2. Apparently, the both classes have a few differences and do not manage authentication in the same way. Hope it helps.
Upvotes: 0