2727
2828import org .slf4j .Logger ;
2929import org .slf4j .LoggerFactory ;
30+ import org .springframework .beans .factory .BeanClassLoaderAware ;
3031import org .springframework .jdbc .core .JdbcOperations ;
3132import org .springframework .jdbc .core .ResultSetExtractor ;
3233import org .springframework .jdbc .core .RowMapper ;
3738import org .springframework .modulith .events .core .PublicationTargetIdentifier ;
3839import org .springframework .transaction .annotation .Transactional ;
3940import org .springframework .util .Assert ;
41+ import org .springframework .util .ClassUtils ;
4042
4143/**
4244 * JDBC-based repository to store {@link EventPublication}s.
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