30
30
31
31
import org .slf4j .Logger ;
32
32
import org .slf4j .LoggerFactory ;
33
+ import org .springframework .beans .factory .BeanClassLoaderAware ;
33
34
import org .springframework .jdbc .core .JdbcOperations ;
34
35
import org .springframework .lang .Nullable ;
35
36
import org .springframework .modulith .events .core .EventPublicationRepository ;
38
39
import org .springframework .modulith .events .core .TargetEventPublication ;
39
40
import org .springframework .transaction .annotation .Transactional ;
40
41
import org .springframework .util .Assert ;
42
+ import org .springframework .util .ClassUtils ;
41
43
42
44
/**
43
45
* JDBC-based repository to store {@link TargetEventPublication}s.
46
48
* @author Björn Kieling
47
49
* @author Oliver Drotbohm
48
50
*/
49
- class JdbcEventPublicationRepository implements EventPublicationRepository {
51
+ class JdbcEventPublicationRepository implements EventPublicationRepository , BeanClassLoaderAware {
50
52
51
53
private static final Logger LOGGER = LoggerFactory .getLogger (JdbcEventPublicationRepository .class );
52
54
@@ -122,6 +124,7 @@ INSERT INTO EVENT_PUBLICATION (ID, EVENT_TYPE, LISTENER_ID, PUBLICATION_DATE, SE
122
124
private final JdbcOperations operations ;
123
125
private final EventSerializer serializer ;
124
126
private final DatabaseType databaseType ;
127
+ private ClassLoader classLoader ;
125
128
126
129
/**
127
130
* Creates a new {@link JdbcEventPublicationRepository} for the given {@link JdbcOperations}, {@link EventSerializer}
@@ -143,6 +146,15 @@ public JdbcEventPublicationRepository(JdbcOperations operations, EventSerializer
143
146
this .databaseType = databaseType ;
144
147
}
145
148
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
+
146
158
/*
147
159
* (non-Javadoc)
148
160
* @see org.springframework.modulith.events.EventPublicationRepository#create(org.springframework.modulith.events.EventPublication)
@@ -326,7 +338,7 @@ private UUID getUuidFromResultSet(ResultSet rs) throws SQLException {
326
338
private Class <?> loadClass (UUID id , String className ) {
327
339
328
340
try {
329
- return Class .forName (className );
341
+ return ClassUtils .forName (className , classLoader );
330
342
} catch (ClassNotFoundException e ) {
331
343
LOGGER .warn ("Event '{}' of unknown type '{}' found" , id , className );
332
344
return null ;
0 commit comments