I am trying to create an OPS4J PAX config DataSource pre-hook to automate database structure integrity checking and updates via Liquibase. According to this tutorial, all I have to do is mark a PreHook
implementation with a @Component
annotation giving it a name property and reference that property in the DataSource config, which I have done.
The problem seems to be that the component is never picked by the SCR.
@Component(property = "name=coredbmigrate")
public class LiquibaseMigrator implements PreHook {
public LiquibaseMigrator() {
System.out.println();
System.out.println("PREHOOK INITIALIZED");
System.out.println();
}
@Override
public void prepare(DataSource dataSource) throws SQLException {
System.out.println();
System.out.println("PREHOOK CALLED");
System.out.println();
}
}
As you can see, I have added basic outputs to indicate when the component is intatiated and called, and neither of those ever happen.
The generated OSGI-INF/lv.cps.is.ledger.accounts.db.LiquibaseMigrator.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<component name="lv.cps.is.ledger.accounts.db.LiquibaseMigrator">
<implementation class="lv.cps.is.ledger.accounts.db.LiquibaseMigrator"/>
<service>
<provide interface="org.ops4j.pax.jdbc.hook.PreHook"/>
</service>
<property name="name" type="String" value="coredbmigrate"/>
</component>
Service-Component
header in MANIFEST.MF
is also set correctly.
What could be the reason that the component is never instantiated? Or maybe it is but I'm not seeing it?
Do you have the scr feature installed? By default it is not installed and in this case DS components are silently ignored.
When it is installed you can use the scr:* commands to check the status of your components.