2016-09-19 1 views
2

Ich habe eine einfache Anwendung mit Spring Boot + Akka. Selten Anwendung schlägt mit Fehlermeldung zeigt dem Schauspieler der Erstellung beginnen:Akka Aktoren können nicht initialisiert werden

<!-- language-all: java --> 
akka.actor.ActorInitializationException: akka://AkkaSystem/user/MyActor: exception during creation 

Ich habe folgende Konfiguration des Frühlings und Akka:

Schauspieler Klasse

@Scope(SCOPE_PROTOTYPE) 
@Component("MyActor") 
public class MyActor extends UntypedActor { 
.... 
} 

SpringActorProducer Klasse

public class SpringActorProducer implements IndirectActorProducer { 
    final ApplicationContext applicationContext; 
    final String actorBeanName; 
    public SpringActorProducer(ApplicationContext applicationContext, 
          String actorBeanName) { 
     this.applicationContext = applicationContext; 
     this.actorBeanName = actorBeanName; 
    } 
    @Override 
    public Actor produce() { 
     return (Actor) applicationContext.getBean(actorBeanName); 
    } 
    @Override 
    public Class<? extends Actor> actorClass() { 
     return (Class<? extends Actor>) applicationContext.getType(actorBeanName); 
    } 
} 

AkkaSpringExtension Klasse

@Component 
public class AkkaSpringExtension implements Extension { 
    private ApplicationContext applicationContext; 

    public void initialize(ApplicationContext applicationContext) { 
     this.applicationContext = applicationContext; 
    } 

    public Props props(String actorBeanName) { 
     return Props.create(SpringActorProducer.class, applicationContext, actorBeanName); 
    } 
} 

und Konfigurationsklasse

@Configuration 
public class AkkaConfiguration { 
    @Autowired 
    private ApplicationContext applicationContext; 

    @Autowired 
    private AkkaSpringExtension springExtension; 

    @Bean 
    public ActorSystem actorSystem() { 
     ExecutorService executor = Executors.newCachedThreadPool(); 
     DelegatingSecurityContextExecutorService executorService = new DelegatingSecurityContextExecutorService(executor); 
     ExecutionContext ec = ExecutionContexts.fromExecutorService(executorService); 
     ActorSystem system = ActorSystem.create("AkkaSystem", customAkkaConfiguration(), this.getClass().getClassLoader(), ec); 

     springExtension.initialize(applicationContext); 
     return system; 
    } 

    @Bean 
    public Config customAkkaConfiguration() { 
     return ConfigFactory.load(); 
    } 
} 

Danach Ich schaffe einen Schauspieler in Körper meines Dienstes:

private ActorRef myActor; 
@Autowired 
private ActorSystem actorSystem; 
@Autowired 
private AkkaSpringExtension springExtension; 

public void afterPropertiesSet() throws Exception { 
    myActor = actorSystem.actorOf(springExtension.props("MyActor"), "MyActor"); 
} 

Normalerweise werden alle Arbeiten wie erwartet, aber manchmal eine Ausnahme tritt auf (möglicherweise 1 von 20 Server-Startups):

MyActor[ERROR] [09/19/2016 10:14:07.705] [pool-3-thread-1] [akka://AkkaSystem/user/MyActor] Error creating bean with name 'MyActor': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: About-to-be-created singleton instance implicitly appeared through the creation of the factory bean that its bean definition points to 
akka.actor.ActorInitializationException: akka://AkkaSystem/user/MyActor: exception during creation 
    at akka.actor.ActorInitializationException$.apply(Actor.scala:174) 
    at akka.actor.ActorCell.create(ActorCell.scala:607) 
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:461) 
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:483) 
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282) 
    at akka.dispatch.Mailbox.run(Mailbox.scala:223) 
    at org.springframework.security.concurrent.DelegatingSecurityContextRunnable.run(DelegatingSecurityContextRunnable.java:83) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 
    at java.lang.Thread.run(Thread.java:785) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyActor': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: About-to-be-created singleton instance implicitly appeared through the creation of the factory bean that its bean definition points to 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:355) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) 
    at com.swissre.cih.configuration.akka.SpringActorProducer.produce(SpringActorProducer.java:17) 
    at akka.actor.Props.newActor(Props.scala:213) 
    at akka.actor.ActorCell.newActor(ActorCell.scala:562) 
    at akka.actor.ActorCell.create(ActorCell.scala:588) 
    ... 8 more 
Caused by: java.lang.IllegalStateException: About-to-be-created singleton instance implicitly appeared through the creation of the factory bean that its bean definition points to 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:378) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:865) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:796) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:544) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:449) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:425) 
    at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1199) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566) 
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) 
    ... 18 more 

Irgendwelche Ideen, was kann falsch sein?

+0

Vielleicht ist dieses Thema irgendwie mit Ihrem Fall verwandt http://stackoverflow.com/questions/31604738/illegalstateexception-thrown-by-spring-during-first-quartz-job-execution –

+0

Vielen Dank für Ihre Hilfe. Erwähnte Fall ist auch über Bean Initialisierung Problem, aber Grundursache ist völlig anders. –

+0

Dann könnten Sie bitte zeigen, was in 'MyActor' Bean ist. Speziell ist es interessant, was dort autowired ist, weil das Protokoll sagt "Injektion von autowired Abhängigkeiten gescheitert". –

Antwort

0

zog ich Schauspieler Initialisierung von afterPropertiesSet zu einem regulären Verfahren, so Schauspieler auf dem ersten Methodenaufruf und Initialisierungsfehler werden verschwunden initialisiert werden.

Verwandte Themen