我有 Spring 服务,它实际上是演员,它接收到信息,但我不能将它传递给另一个 Spring 服务,因为注入失败。
@Service("mailContainer")
@Scope("prototype")
@Component
public class MailContainer extends UntypedActor {
private final LoggingAdapter LOG = Logging.getLogger(getContext().system(), this);
private Mail value;
private List<Mail> mailList = new ArrayList<Mail>();
private Integer size;
@Autowired
@Qualifier("springService")
private SpringService springService;
//@Autowired
public void setSpringService(SpringService springService) {
this.springService = springService;
}
public MailContainer(Mail value) {
this.value = value;
}
@Override
public void onReceive(Object message) throws Exception {
// LOG.debug("+ MailContainer message: {} ", message);
if (message instanceof Mail) {
value = (Mail) message;
System.out.println("MailContainer get message with id " + value.getId());
System.out.println("With time " + value.getDateSend());
//getSender().tell(value, getSelf()); //heta uxarkum
//this.saveIt(value);
springService.add(value);
}
}
和第二次服务
@Service("springService")
//@Component
@Scope("session")
public class SpringService {
private List<Mail> mailList = new ArrayList<Mail>();
public void add(Mail mail) {
System.out.println("Saving mail from Spring " +mail.getId());
mailList.add(mail);
}
public List<Mail> getMailList() {
return mailList;
}
}
Spring 配置,这是来自 akka spring 示例
@Configuration
//@EnableScheduling
//EnableAsync
@ComponentScan(basePackages = {"com"}, excludeFilters = {
@ComponentScan.Filter(Configuration.class)})
//@ImportResource("classpath:META-INF/spring/spring-data-context.xml")
//@EnableTransactionManagement
//@EnableMBeanExport
//@EnableWebMvc
public class CommonCoreConfig {
// the application context is needed to initialize the Akka Spring Extension
@Autowired
private ApplicationContext applicationContext;
/**
* Actor system singleton for this application.
*/
@Bean
public ActorSystem actorSystem() {
ActorSystem system = ActorSystem.create("AkkaJavaSpring");
// initialize the application context in the Akka Spring Extension
SpringExtProvider.get(system).initialize(applicationContext);
return system;
}
}
那么,我如何才能注入另一个 Spring 服务?????????