Wrong applicationId fixed in case of context refresh (#811)

Signed-off-by: Dominic Schabel <dominic.schabel@bosch-si.com>
This commit is contained in:
Dominic Schabel
2019-03-26 06:59:01 +01:00
committed by Stefan Behl
parent 51be28147f
commit 56b938d22b

View File

@@ -10,23 +10,23 @@ package org.eclipse.hawkbit.repository.model.helper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
/**
* A singleton bean which holds the event publisher to have to the cache manager
* in beans not instantiated by spring e.g. JPA entities or
* CacheFieldEntityListener which cannot be autowired.
*
*/
public final class EventPublisherHolder {
public final class EventPublisherHolder implements ApplicationContextAware {
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
@Autowired
private ApplicationEventPublisher eventPublisher;
@Autowired
private BusProperties bus;
private String applicationId;
private EventPublisherHolder() {
@@ -47,7 +47,11 @@ public final class EventPublisherHolder {
}
public String getApplicationId() {
return bus.getId();
return applicationId;
}
@Override
public void setApplicationContext(final ApplicationContext applicationContext) {
applicationId = applicationContext.getBean(BusProperties.class).getId();
}
}