Java Akka Spring延伸儿童演员烦恼

时间:2016-04-18 15:22:10

标签: java spring akka

我有这个Akka Spring扩展名:

    // ...    
    @Service("springExtension")
    public class SpringExtension implements Extension {

        @Autowired
        private ApplicationContext applicationContext;

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

        public Props props(String actorBeanName, Object... args) {
            return (args != null && args.length > 0)
                    ? Props.create(SpringActorProducer.class, applicationContext, actorBeanName, args)
                    : props(actorBeanName);
        }
    }

和这个演员制作人:

    // ...    
    public class SpringActorProducer implements IndirectActorProducer {

        final ApplicationContext applicationContext;
        final String actorBeanName;
        final Object[] args;

        public SpringActorProducer(ApplicationContext applicationContext, String actorBeanName) {
            this.applicationContext = applicationContext;
            this.actorBeanName = actorBeanName;
            this.args = null;
        }

        public SpringActorProducer(ApplicationContext applicationContext, String actorBeanName, Object... args) {
            this.applicationContext = applicationContext;
            this.actorBeanName = actorBeanName;
            this.args = args;
        }

        @Override
        public Actor produce() {
            return args == null
                    ? (Actor) applicationContext.getBean(actorBeanName)
                    : (Actor) applicationContext.getBean(actorBeanName, args);
        }

        @Override
        public Class<? extends Actor> actorClass() {
            return (Class<? extends Actor>) applicationContext.getType(actorBeanName);
        }
    }

ActroSystem和actor创建没有问题:

@Service("actorSystemService")
public class ActorSystemServiceImpl implements ActorSystemService {

    @Autowired
    private SpringExtension springExtension;

    @PostConstruct
    public void start() {
        ActorSystem system = ActorSystem.create("MyActorSystem");
        projectService = system.actorOf(springExtension.props("projectService"));
    }

一切都还不错:

@Component("projectService")
public class ProjectService extends AbstractActor {

@Autowired
private SpringExtension springExtension;

// ...
    getContext().actorOf(springExtension.props("projectActor", name).forward(msg, getContext());
// ...

但是有一个问题:

@Component("projectActor")
@Scope("prototype")
public class ProjectActor extends UntypedActorWithStash {

    @Autowired
    private ProjectDAO dao; // <-- this is null ?!
    // ...

为什么所有@Autowired都为null?

0 个答案:

没有答案