Home > database >  Spring Artemis Dependencies conflict - how to resolve
Spring Artemis Dependencies conflict - how to resolve

Time:12-30

Statement of problem:

I am refactoring my application from Spring 5.x to Spring 6.0.0 .

Due to changes in the java API's imposed by Oracle, some dependencies have been forced to be changed.

There appears to be a dependency conflict where the org.springframework.jms.listener.MessageListenerContainer requires a jakarta.jms.ConnectionFactory, but the org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory extends the older javax.jms.ConnectionFactory .

I suspect that there is a POM dependency that I am missing, but I have been unable to resolve it.

POM excerpt:

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-xml</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-core</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-flow</artifactId>
            <version>1.0.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-jms</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-jdbc</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-file</artifactId>
            <version>6.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-jms-client</artifactId>
            <version>2.27.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>artemis-spring-integration</artifactId>
            <version>2.27.1</version>
        </dependency>

Code Snip:

    // ActiveMQConnectionFactory implements javax.jms.ConnectionFactory
    @Order(0)
    public ActiveMQConnectionFactory connectionFactory() throws JMSException {
        if (connectionFactory == null) {
            connectionFactory = new ActiveMQConnectionFactory();
            PropertyValue pv = configPropertiesService.fetchPropertyValue(PropertyValueConstants.ACTIVEMQ_BROKER_URL,
                    PropertyValueConstants.ACTIVEMQ_BROKER_URL_DEFAULT);
            PropertyValue pvu = configPropertiesService.fetchPropertyValue(PropertyValueConstants.ACTIVEMQ_BROKER_UNAME,
                    PropertyValueConstants.ACTIVEMQ_BROKER_USERNAME_DEFAULT);
            PropertyValue pvp = configPropertiesService.fetchPropertyValue(PropertyValueConstants.ACTIVEMQ_BROKER_PASS,
                    PropertyValueConstants.ACTIVEMQ_BROKER_PASS_DEFAULT);
            connectionFactory.setBrokerURL(pv.getValue());
            connectionFactory.setPassword(pvp.getValue());
        }

        return connectionFactory;
    }

    @Bean(name = "MessageDrivenAdapter")
    public MessageListenerContainer getContainer() {
        DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
        container.setConnectionFactory(connectionFactory());  // requires jakarta.jms.ConnectionFactory
        container.setDestinationName("requestsQueue");
        container.setMessageListener(messageListener());
        container.setAutoStartup(false);
        container.setTaskExecutor(stepTaskExecutor);
        container.setConcurrentConsumers(5);

        return container;
    }

CodePudding user response:

ActiveMQ developers provide two flavours of their library (seems to be the most sober approach for that messy javax -> jakarta transition):

You need the second one.

  • Related