我有这个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);
}
}
Run Code Online (Sandbox Code Playgroud)
这个演员制片人:
// ...
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);
}
}
Run Code Online (Sandbox Code Playgroud)
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"));
}
Run Code Online (Sandbox Code Playgroud)
那里一切都还好:
@Component("projectService")
public class ProjectService extends AbstractActor {
@Autowired
private SpringExtension springExtension;
// ...
getContext().actorOf(springExtension.props("projectActor", name).forward(msg, getContext());
// ...
Run Code Online (Sandbox Code Playgroud)
但有个问题:
@Component("projectActor")
@Scope("prototype")
public class ProjectActor extends UntypedActorWithStash {
@Autowired
private ProjectDAO dao; // <-- this is null ?!
// ...
Run Code Online (Sandbox Code Playgroud)
为什么所有@Autowired为null?
| 归档时间: |
|
| 查看次数: |
296 次 |
| 最近记录: |