Spring boot ejb如何使用springbootbean?

Spring boot ejb如何使用springbootbean?,spring-boot,glassfish-3,Spring Boot,Glassfish 3,使用我们在中发现的想法: 我们希望使用拦截器从EJB访问spring引导bean。但问题是,文档的示例使用了新的上下文 EJB如何访问spring引导上下文 我们试过这样做: public class MySpringActuatorMetricsCoreTestInterceptor extends SpringBeanAutowiringInterceptor { //Spring boot application context @Autowired A

使用我们在中发现的想法:

我们希望使用拦截器从EJB访问spring引导bean。但问题是,文档的示例使用了新的上下文

EJB如何访问spring引导上下文

我们试过这样做:

public class MySpringActuatorMetricsCoreTestInterceptor extends SpringBeanAutowiringInterceptor {

        //Spring boot application context
    @Autowired
    ApplicationContext applicationContext;

    @SuppressWarnings("resource")
    @Override
    protected BeanFactory getBeanFactory(Object target) {
        return applicationContext.getAutowireCapableBeanFactory();
    }

}
EBJ看起来像这样:

// ejb
@Stateless
// spring
@Interceptors(MySpringActuatorMetricsCoreTestInterceptor.class)
public class FirstBean {
[...]
问题是:应用程序上下文尚未初始化,因为EJB初始化发生在之前,因此->空指针异常

我们认为有两种选择: -我们以某种方式从spring引导中获取应用程序上下文。 -我们可以将MySpringActuatorMetricsCoreTestInterceptor创建的上下文提供给spring引导上下文

有什么解决办法吗?另一种选择

我们正在使用Glassfish 3.1


谢谢

好吧,我找到了一个方法: 我刚刚在我的类路径中添加了一个beanRefContext.xml:

它也在我的类路径中引用了名为simpleContext.xml的新applicationContext文件:

...
<!-- Enable annotation support within our beans -->
<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="your.package.path" />
<context:property-placeholder location="classpath*:*.properties" />
}


不过,现在这只是一个小的hello world示例,我不确定Spring服务是否仍然可以引用Spring boot初始化的资源。这需要我做进一步的测试。

ejb和Spring引导对我来说似乎是正交的。我喜欢弹簧和弹簧靴。放弃EJB。我也没有找到一种方法,最好的办法可能是使用SpringBoot和SpringREST将服务公开为rest服务。但是,在spring boot中使用EJB是可能的。好的,我刚刚针对一个使用db的服务评估了这个方法,它似乎可以工作,该服务仍然访问我的db并返回正确的值。好的,看起来,您必须为spring boot应用程序添加整个组件扫描。然后,SpringBoot将使用自己的应用程序上下文为ejb基础结构启动第二次启动。这样,通过ejb和应用程序实例共享配置。但是,您必须记住,您现在在运行的应用程序中处理两个独立的应用程序上下文,一个用于主应用程序,另一个用于EJB。不幸的是,SpringBeanAutowiringInterceptor已在Spring 5中删除:
@Stateless(name = "RightsServiceEJB")
@Remote
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class RightsServiceEJB implements IRightsServiceEJB {

   @Autowired
   ExampleService exampleService;

   @Override
   public String sayHello() {
      return exampleService.sayHello();
   }