Spring Boot 2 重新部署到 Wildfly 10 后无法刷新 JMS 连接

Posted

技术标签:

【中文标题】Spring Boot 2 重新部署到 Wildfly 10 后无法刷新 JMS 连接【英文标题】:Spring Boot 2 Could not refresh JMS Connection after redeployment to Wildfly 10 【发布时间】:2019-12-26 23:53:15 【问题描述】:

在 Spring 上运行良好,但在 Spring Boot 2 上运行良好。

在 WAR 重新部署到 Wildfly 10 JMS 后停止工作并出现错误:

错误 [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-1) 无法刷新目标“wfQueue”的 JMS 连接 - 使用 FixedBackOffinterval=5000, currentAttempts=44, maxAttempts=unlimited 重试。原因:创建会话工厂失败;嵌套异常是 java.lang.IllegalStateException: 服务器定位器已关闭(可能是垃圾收集)

重启可解决问题,但停机时间不可取。

依赖:

        <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.2.0</version>
    </dependency>





    <!-- Spring -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
          </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
       <groupId>org.hibernate</groupId>
       <artifactId>hibernate-entitymanager</artifactId>
       <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId>
    </dependency>



    <!-- Appache commons -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- POI -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.10-FINAL</version>           
    </dependency>

    <!-- For documents at the stmt screene -->
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
    </dependency>



    <!-- Gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>

    <!-- Mail -->
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>

    <!-- xstream -->
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.9</version>
    </dependency>


    <!--############################# JSP RELATED ####################### -->
    <!-- JSP Dependency -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
    </dependency>

    <!-- Servlet Dependency -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
    </dependency>


    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>javax.servlet.jsp.jstl-api</artifactId>
        <version>1.2.1</version>
    </dependency>

    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>





    <dependency>
        <groupId>displaytag</groupId>
        <artifactId>displaytag</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>           
    </dependency>


    <dependency>
        <groupId>org.apache.taglibs</groupId>
        <artifactId>taglibs-standard-impl</artifactId>
        <version>1.2.5</version>
    </dependency>

    <!-- EJB -->
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-remote-naming</artifactId>
        <version>2.0.4.Final</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-nio</artifactId>
        <version>3.4.2.Final</version>
    </dependency>


    <dependency>
        <groupId>org.jboss.marshalling</groupId>
        <artifactId>jboss-marshalling</artifactId>
        <version>1.4.11.Final</version>
    </dependency>

    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-ejb-client-bom</artifactId>
        <version>10.0.0.Final</version>
        <type>pom</type>
    </dependency>

【问题讨论】:

【参考方案1】:

从这里How connect to WildFly 10.1.0.Final ActiveMQ Artemis using JNDI and Spring?

1) 从 application.properties 中删除 spring.jms.jndi-name=java:/ConnectionFactory

2) 添加到启动配置

 public ConnectionFactory notificacionesConnectionFactory() throws IllegalArgumentException, NamingException 
     JndiObjectFactoryBean jndi = new JndiObjectFactoryBean();
     jndi.setJndiName("java:/ConnectionFactory");
     jndi.setLookupOnStartup(true);
     jndi.setProxyInterface(ConnectionFactory.class);
     jndi.afterPropertiesSet();
     return  new  SingleConnectionFactory((ConnectionFactory)jndi.getObject());
 

【讨论】:

以上是关于Spring Boot 2 重新部署到 Wildfly 10 后无法刷新 JMS 连接的主要内容,如果未能解决你的问题,请参考以下文章

SPRING BOOT 手动 War 文件部署到 Tomcat 并重新启动服务器,不创建数据库

Spring Boot2.0之热部署原理

Spring Boot 热部署

如何使用spring dev工具在docker中自动重新加载spring boot应用程序

Spring Boot 热部署(转)

Spring Boot使用Maven工具自动重启SpringBoot项目 | 热部署