Skip to content

Commit 1d63f0b

Browse files
committed
GH-631 - Let JdbcEventPublicationRepository implement BeanClassLoaderAware.
To make sure the event type is loaded via the RestartClassLoader when using Spring Boot Devtools.
1 parent 3c7c448 commit 1d63f0b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
33+
import org.springframework.beans.factory.BeanClassLoaderAware;
3334
import org.springframework.jdbc.core.JdbcOperations;
3435
import org.springframework.lang.Nullable;
3536
import org.springframework.modulith.events.core.EventPublicationRepository;
@@ -38,6 +39,7 @@
3839
import org.springframework.modulith.events.core.TargetEventPublication;
3940
import org.springframework.transaction.annotation.Transactional;
4041
import org.springframework.util.Assert;
42+
import org.springframework.util.ClassUtils;
4143

4244
/**
4345
* JDBC-based repository to store {@link TargetEventPublication}s.
@@ -46,7 +48,7 @@
4648
* @author Björn Kieling
4749
* @author Oliver Drotbohm
4850
*/
49-
class JdbcEventPublicationRepository implements EventPublicationRepository {
51+
class JdbcEventPublicationRepository implements EventPublicationRepository, BeanClassLoaderAware {
5052

5153
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcEventPublicationRepository.class);
5254

@@ -122,6 +124,7 @@ INSERT INTO EVENT_PUBLICATION (ID, EVENT_TYPE, LISTENER_ID, PUBLICATION_DATE, SE
122124
private final JdbcOperations operations;
123125
private final EventSerializer serializer;
124126
private final DatabaseType databaseType;
127+
private ClassLoader classLoader;
125128

126129
/**
127130
* Creates a new {@link JdbcEventPublicationRepository} for the given {@link JdbcOperations}, {@link EventSerializer}
@@ -143,6 +146,15 @@ public JdbcEventPublicationRepository(JdbcOperations operations, EventSerializer
143146
this.databaseType = databaseType;
144147
}
145148

149+
/*
150+
* (non-Javadoc)
151+
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
152+
*/
153+
@Override
154+
public void setBeanClassLoader(ClassLoader classLoader) {
155+
this.classLoader = classLoader;
156+
}
157+
146158
/*
147159
* (non-Javadoc)
148160
* @see org.springframework.modulith.events.EventPublicationRepository#create(org.springframework.modulith.events.EventPublication)
@@ -326,7 +338,7 @@ private UUID getUuidFromResultSet(ResultSet rs) throws SQLException {
326338
private Class<?> loadClass(UUID id, String className) {
327339

328340
try {
329-
return Class.forName(className);
341+
return ClassUtils.forName(className, classLoader);
330342
} catch (ClassNotFoundException e) {
331343
LOGGER.warn("Event '{}' of unknown type '{}' found", id, className);
332344
return null;

0 commit comments

Comments
 (0)