In blueprint.xml
, I declare an optional dependency this way:
<reference id="RepositoryListener"
interface="ru.focusmedia.odp.server.datastore.api.RepositoryListener"
availability="optional" />
<bean id="Repository"
class="ru.focusmedia.odp.server.datastore.jpa.repository.RepositoryImpl">
<jpa:context property="entityManager" unitname="ODP_Server" />
<tx:transaction method="*" value="Required" />
<property name="repositoryListener" ref="RepositoryListener" />
</bean>
and in RepositoryImpl
, I have
public void setRepositoryListener(RepositoryListener repositoryListener) {
logger.info("Repository listener set");
this.repositoryListener = repositoryListener;
}
This method is called by Blueprint even when there is no RepositoryListener
service available, as expected. The problem is, how can I check later whether there is a service?
if (repositoryListener != null) {
repositoryListener.notifyDelete(node);
} else {
logger.warn("No repository listener set!");
}
doesn't work, since repositoryListener
isn't null
, but a Blueprint proxy.
Repository
bean. – Homosexual