3030
3131import org .slf4j .Logger ;
3232import org .slf4j .LoggerFactory ;
33+ import org .springframework .beans .factory .BeanClassLoaderAware ;
3334import org .springframework .jdbc .core .JdbcOperations ;
3435import org .springframework .lang .Nullable ;
3536import org .springframework .modulith .events .core .EventPublicationRepository ;
3839import org .springframework .modulith .events .core .TargetEventPublication ;
3940import org .springframework .transaction .annotation .Transactional ;
4041import org .springframework .util .Assert ;
42+ import org .springframework .util .ClassUtils ;
4143
4244/**
4345 * JDBC-based repository to store {@link TargetEventPublication}s.
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