Adding a detail: The @Reference annotation is deprecated.
****************************
For creating a JDBC connection pool (to mariadb) in Sling 11, I followed
the instructions given at
https://sling.apache.org/documentation/bundles/datasource-providers.html
. However, I get a runtime exception on the datasource without further
details.
As documented on that webpage, I declared the following in the consuming
class:
import org.apache.felix.scr.annotations.Reference;
public class Database {
@Reference(target =
"(&(objectclass=javax.sql.DataSource)(datasource.name=dbdb))")
DataSource dataSource;
public String test() {
try {
Connection con = dataSource.getConnection();
... Some SQL instructions...
}
The config of the datasource was done via the Felix console and looks like:
in JNDI DataSource:
Datasource name(*): dbdb
JNDI name(*): dbdb
in Apache Sling Connection Pooled DataSource:
Datasource name(*): dbdb
JDBC driver class: org.mariadb.jdbc.Driver
JDBC connection URI:
jdbc:mysql://localhost:3306/someDB?useUnicode=yes&characterEncoding=UTF-8
Username: xyz
.... many more
The POM:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.12.0</version>
</dependency>
Now, the datasource, at the moment of calling test() is null. I have
absolutely no hint what the problem is. The config? The annotation? What
is obvious, however, is that the /@Reference /as suggested on the
bundles page, is deprecated... What would be the most current approach?
Thanks,
-Juerg