JASON 内部操作是否适用于 Spring Autowire?



我正在使用JADE,JASON(代理框架(和Spring Boot开发一个应用程序。基本上我有一个翡翠容器,翡翠和翡翠代理都在其中注册。由于我使用的是Spring,所以我倾向于自动线服务。在这种情况下,我需要访问一些服务,在我的一些 Jason 内部操作中(我自定义编写扩展 DefaultInternalAction 类(。这似乎不起作用。我知道如何自动接线以及豆子如何工作。我怀疑这些内部行动是否在春季背景下。我想他们不是。这就是为什么可能是自动线的东西不起作用。有人可以解释一下玉容器内的实际动作和内部动作,以便我可以以不同的方式思考在杰森内部动作中使用 Autowire 。

据我所知,内部操作是由 jason 创建的,而不是 spring,这就是为什么你不能自动连接服务。就个人而言,我创建了工厂并使用它来获取服务的实例。像这样:

public class SpringPluginFactory {
private static final SpringPluginFactory INSTANCE = new SpringPluginFactory();
private ApplicationContext applicationContext;
private SpringPluginFactory(){}
private <T> T createPlugin(Class<T> iface) {
if(applicationContext == null){
throw new IllegalStateException("applicationContext cannot be null");
}
try {
return applicationContext.getBean(iface);
} catch (Exception e) {
throw new RuntimeException("factory unable to construct instance of " + iface.getName());
}
}
public static <T> T getPlugin(Class<T> iface){
return INSTANCE.createPlugin(iface);
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

}

然后我创建 bean 以设置应用程序上下文:

@Bean
public SpringPluginFactory pluginFactory(ApplicationContext applicationContext){
SpringPluginFactory pluginFactory = SpringPluginFactory.INSTANCE;
pluginFactory.setApplicationContext(applicationContext);
return pluginFactory;
}

并在任何行为或内部行为中使用工厂

SpringPluginFactory.getPlugin(YouService.class).doSomething();

也许它会有所帮助。

最新更新