Fix issue with devtools

- Where class is resolved, use ClassLoader from
  BeanClassLoaderAware which is the one working
  with devtools.
- Fixes #531
This commit is contained in:
Janne Valkealahti
2018-03-12 19:59:35 +00:00
parent 30987d3eb7
commit 0df3f9a898
2 changed files with 20 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -131,7 +132,7 @@ public class StateMachineConfiguration<S, E> extends
private static class StateMachineDelegatingFactoryBean<S, E>
extends BeanDelegatingFactoryBean<StateMachine<S, E>,StateMachineConfigBuilder<S, E>,StateMachineConfig<S, E>>
implements SmartLifecycle, BeanNameAware {
implements SmartLifecycle, BeanNameAware, BeanClassLoaderAware {
private String clazzName;
private Boolean contextEvents;
@@ -139,6 +140,7 @@ public class StateMachineConfiguration<S, E> extends
private DisposableBean disposableBean;
private String beanName;
private StateMachineMonitor<S, E> stateMachineMonitor;
private ClassLoader classLoader;
public StateMachineDelegatingFactoryBean(StateMachineConfigBuilder<S, E> builder, Class<StateMachine<S, E>> clazz,
String clazzName, Boolean contextEvents) {
@@ -152,11 +154,17 @@ public class StateMachineConfiguration<S, E> extends
this.beanName = name;
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@SuppressWarnings("unchecked")
@Override
public void afterPropertiesSet() throws Exception {
AnnotationConfigurer<StateMachineConfig<S, E>, StateMachineConfigBuilder<S, E>> configurer =
(AnnotationConfigurer<StateMachineConfig<S, E>, StateMachineConfigBuilder<S, E>>) getBeanFactory().getBean(Class.forName(clazzName));
(AnnotationConfigurer<StateMachineConfig<S, E>, StateMachineConfigBuilder<S, E>>) getBeanFactory()
.getBean(ClassUtils.forName(clazzName, classLoader));
getBuilder().apply(configurer);
StateMachineConfig<S, E> stateMachineConfig = getBuilder().getOrBuild();

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
@@ -111,13 +112,14 @@ public class StateMachineFactoryConfiguration<S, E> extends
}
private static class StateMachineFactoryDelegatingFactoryBean<S, E> implements
FactoryBean<StateMachineFactory<S, E>>, BeanFactoryAware, InitializingBean {
FactoryBean<StateMachineFactory<S, E>>, BeanFactoryAware, InitializingBean, BeanClassLoaderAware {
private final StateMachineConfigBuilder<S, E> builder;
private BeanFactory beanFactory;
private StateMachineFactory<S, E> stateMachineFactory;
private String clazzName;
private Boolean contextEvents;
private ClassLoader classLoader;
@SuppressWarnings("unused")
public StateMachineFactoryDelegatingFactoryBean(StateMachineConfigBuilder<S, E> builder, String clazzName, Boolean contextEvents) {
@@ -141,11 +143,17 @@ public class StateMachineFactoryConfiguration<S, E> extends
return true;
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@SuppressWarnings("unchecked")
@Override
public void afterPropertiesSet() throws Exception {
AnnotationConfigurer<StateMachineConfig<S, E>, StateMachineConfigBuilder<S, E>> configurer =
(AnnotationConfigurer<StateMachineConfig<S, E>, StateMachineConfigBuilder<S, E>>) beanFactory.getBean(Class.forName(clazzName));
(AnnotationConfigurer<StateMachineConfig<S, E>, StateMachineConfigBuilder<S, E>>) beanFactory
.getBean(ClassUtils.forName(clazzName, classLoader));
builder.apply(configurer);
StateMachineConfig<S, E> stateMachineConfig = builder.getOrBuild();