Skip to content

Commit a42539a

Browse files
committed
GH-632 - Let JdbcEventPublicationRepository implement BeanClassLoaderAware.
To make sure the event type is loaded via the RestartClassLoader when using Spring Boot Devtools.
1 parent 5fb6add commit a42539a

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
@@ -27,6 +27,7 @@
2727

2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
30+
import org.springframework.beans.factory.BeanClassLoaderAware;
3031
import org.springframework.jdbc.core.JdbcOperations;
3132
import org.springframework.jdbc.core.ResultSetExtractor;
3233
import org.springframework.jdbc.core.RowMapper;
@@ -37,6 +38,7 @@
3738
import org.springframework.modulith.events.core.PublicationTargetIdentifier;
3839
import org.springframework.transaction.annotation.Transactional;
3940
import org.springframework.util.Assert;
41+
import org.springframework.util.ClassUtils;
4042

4143
/**
4244
* JDBC-based repository to store {@link EventPublication}s.
@@ -45,7 +47,7 @@
4547
* @author Björn Kieling
4648
* @author Oliver Drotbohm
4749
*/
48-
class JdbcEventPublicationRepository implements EventPublicationRepository {
50+
class JdbcEventPublicationRepository implements EventPublicationRepository, BeanClassLoaderAware {
4951

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

@@ -102,6 +104,7 @@ INSERT INTO EVENT_PUBLICATION (ID, EVENT_TYPE, LISTENER_ID, PUBLICATION_DATE, SE
102104
private final JdbcOperations operations;
103105
private final EventSerializer serializer;
104106
private final DatabaseType databaseType;
107+
private ClassLoader classLoader;
105108

106109
/**
107110
* Creates a new {@link JdbcEventPublicationRepository} for the given {@link JdbcOperations}, {@link EventSerializer}
@@ -123,6 +126,15 @@ public JdbcEventPublicationRepository(JdbcOperations operations, EventSerializer
123126
this.databaseType = databaseType;
124127
}
125128

129+
/*
130+
* (non-Javadoc)
131+
* @see org.springframework.beans.factory.BeanClassLoaderAware#setBeanClassLoader(java.lang.ClassLoader)
132+
*/
133+
@Override
134+
public void setBeanClassLoader(ClassLoader classLoader) {
135+
this.classLoader = classLoader;
136+
}
137+
126138
/*
127139
* (non-Javadoc)
128140
* @see org.springframework.modulith.events.EventPublicationRepository#create(org.springframework.modulith.events.EventPublication)
@@ -270,7 +282,7 @@ private UUID getUuidFromResultSet(ResultSet rs) throws SQLException {
270282
private Class<?> loadClass(UUID id, String className) {
271283

272284
try {
273-
return Class.forName(className);
285+
return ClassUtils.forName(className, classLoader);
274286
} catch (ClassNotFoundException e) {
275287
LOGGER.warn("Event '{}' of unknown type '{}' found", id, className);
276288
return null;

0 commit comments

Comments
 (0)