GH-631 - Let JdbcEventPublicationRepository implement BeanClassLoaderAware.
To make sure the event type is loaded via the RestartClassLoader when using Spring Boot Devtools.
This commit is contained in:
@@ -30,6 +30,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.modulith.events.core.EventPublicationRepository;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.modulith.events.core.PublicationTargetIdentifier;
|
||||
import org.springframework.modulith.events.core.TargetEventPublication;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* JDBC-based repository to store {@link TargetEventPublication}s.
|
||||
@@ -46,7 +48,7 @@ import org.springframework.util.Assert;
|
||||
* @author Björn Kieling
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
class JdbcEventPublicationRepository implements EventPublicationRepository {
|
||||
class JdbcEventPublicationRepository implements EventPublicationRepository, BeanClassLoaderAware {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcEventPublicationRepository.class);
|
||||
|
||||
@@ -122,6 +124,7 @@ class JdbcEventPublicationRepository implements EventPublicationRepository {
|
||||
private final JdbcOperations operations;
|
||||
private final EventSerializer serializer;
|
||||
private final DatabaseType databaseType;
|
||||
private ClassLoader classLoader;
|
||||
|
||||
/**
|
||||
* Creates a new {@link JdbcEventPublicationRepository} for the given {@link JdbcOperations}, {@link EventSerializer}
|
||||
@@ -143,6 +146,15 @@ class JdbcEventPublicationRepository implements EventPublicationRepository {
|
||||
this.databaseType = databaseType;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
|
||||
*/
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.modulith.events.EventPublicationRepository#create(org.springframework.modulith.events.EventPublication)
|
||||
@@ -326,7 +338,7 @@ class JdbcEventPublicationRepository implements EventPublicationRepository {
|
||||
private Class<?> loadClass(UUID id, String className) {
|
||||
|
||||
try {
|
||||
return Class.forName(className);
|
||||
return ClassUtils.forName(className, classLoader);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOGGER.warn("Event '{}' of unknown type '{}' found", id, className);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user