简体   繁体   English

带有 Spring Boot 2.3 的 Jpos Q2 服务器

[英]Jpos Q2 Server with Spring boot 2.3

We have a existing system with Q2 Server and Spring MVC with following configuration.我们有一个带有 Q2 Server 和 Spring MVC 的现有系统,配置如下。 Q2 server was created when a Httpservlet is initiated and It worked perfectly and spring beans can be autowired withn ISORequestlistner. Q2 服务器是在 Httpservlet 启动时创建的,它运行良好,Spring bean 可以使用 ISORequestlistner 自动装配。 This is now being converted to Spring boot 2.3.现在正在转换为 Spring boot 2.3。 Once I initiated the same Httpservlet using ServletRegistrationBean in Spring boot, Q2 server is initiated and can send requst to it.一旦我在 Spring Boot 中使用 ServletRegistrationBean 启动了相同的 Httpservlet,Q2 服务器就会启动并且可以向它发送请求。 But auto-wiring is not working.但是自动接线不起作用。 Once I check.一旦我检查。 Once he request is processing inside the ISORequest listner, Spring context is not visible since Q2 server is using different class loader.一旦他的请求在 ISORequest 侦听器中处理,Spring 上下文就不可见,因为 Q2 服务器使用不同的类加载器。

 <server class="org.jpos.q2.iso.QServer" logger="Q2" name="DownloadServer-A"> <attr name="port" type="java.lang.Integer">6400</attr> <attr name="minSessions" type="java.lang.Integer">10</attr> <attr name="maxSessions" type="java.lang.Integer">1100</attr> <channel name="DownloadServer-A-Channel" class="org.jpos.iso.channel.NACChannel" logger="Q2" packager="org.jpos.iso.packager.GenericPackager" header="6000010000"> <property name="packager-config" value="/app/repository/q2serverconfig/resources/Download_generic.xml" /> </channel> <request-listener class="DownloadServerAListener" logger="Q2"> <property name="space" value="transient:default" /> <property name="queue" value="TransactionQueue" /> <property name="timeout" value="35000" /> </request-listener> </server>
1st Try Tried creating static ApplicationContext using ApplicationContextAware and tried it in the ISORequestListner. 第一次尝试尝试使用 ApplicationContextAware 创建静态 ApplicationContext 并在 ISORequestListner 中尝试。 But It becomes null when TCP request received to Q2 server. 但是当 TCP 请求接收到 Q2 服务器时它变为空。

2nd Try I tried several solutions like below github repo.第二次尝试我尝试了几种解决方案,如下面的 github repo。 But I didn't work.但我没有工作。 https://github.com/vmantek/chimera https://github.com/vmantek/chimera

Have anyone tried to start ISO Server inside the Spring Application context as a bean?有没有人尝试在 Spring Application 上下文中作为 bean 启动 ISO Server? What I mean is that start ISO Server in @Configuration class with using Q2.start().我的意思是使用 Q2.start() 在 @Configuration 类中启动 ISO 服务器。 Q2.start will start in a separate class loader. Q2.start 将在单独的类加载器中启动。 I don't want it to happen.我不希望它发生。

I was looking for these few days and I was trying several ways.这几天我一直在寻找,我尝试了几种方法。 The issue is that Spring is starting in a Specific class loader.问题是 Spring 在特定类加载器中启动。 But when you start Q2 Server as但是当你启动 Q2 Server 时

Q2 q2Server = new Q2(<deploydir>);
q2Server.start();

Q2 server is starting in a different classloader. Q2 服务器在不同的类加载器中启动。 Therefore SpringContext was not available for auto wiring.因此 SpringContext 不可用于自动装配。 SpringBeanAutowiringSupport depends on ContextLoader to retrieve the current application context, and always get null. SpringBeanAutowiringSupport 依赖于 ContextLoader 来检索当前的应用程序上下文,并且总是获取 null。

Workaround解决方法

You could register a bean that implements org.springframework.boot.context.embedded.ServletContextInitializer to retrieve the application context during startup().您可以注册一个实现 org.springframework.boot.context.embedded.ServletContextInitializer 的 bean 以在启动期间检索应用程序上下文。

@Configuration
public class WebApplicationContextLocator implements ServletContextInitializer {
    private static WebApplicationContext webApplicationContext;

    public static WebApplicationContext getCurrentWebApplicationContext() {
        return webApplicationContext;
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
      webApplicationContext = 
            WebApplicationContextUtils.getWebApplicationContext(servletContext);
    }
}

Then you could implement self-autowiring in your ISORequestListener class.然后你可以在你的 ISORequestListener 类中实现自我自动装配。

 @Component
 public class ServiceImpl implements ISORequestListener {
    @Autowired
    private BackendService backendService;

    public ServiceImpl() {
           AutowiredAnnotationBeanPostProcessor bpp = new 
                       AutowiredAnnotationBeanPostProcessor();
           WebApplicationContext currentContext = 
                       WebApplicationContextLocator.getCurrentWebApplicationContext();
           bpp.setBeanFactory(currentContext.getAutowireCapableBeanFactory());
           bpp.processInjection(this);
    }

}

Then auto wiring working perfectly.然后自动接线工作完美。 I was inspired by following answer.我受到以下答案的启发。 Spring Boot register JAX-WS webservice as bean Spring Boot 将 JAX-WS webservice 注册为 bean

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM