1

I have been upgrading one of the app to spring framwork 5.X from 3.X, one of the problem I am failing to resolve it error is following - this makes a use of spring-jms

cannot access org.springframework.context.SmartLifecycle [ERROR]
class file for org.springframework.context.SmartLifecycle not found

I can see last version the exact same code works with Spring 4.3.9 (last of 4.X release) and breaks with Spring 5.0.0 (First of 5.X releases)

I don't see my code exposing the class SmartLifecycle but I have suspicion that DefaultMessageListenerContainer instance is at a fault.

public class Factory {
    private DefaultMessageListenerContainer testListnerService;

    public void start() {

        final TestMessageListener testMessageListener = new TestMessageListener();
        testListnerService = new DefaultMessageListenerContainer();    <-- This is where compilation breaks
        testListnerService.setMessageListener(testMessageListener);
        testListnerService.setSessionTransacted(true);
        testListnerService.afterPropertiesSet();
    }

I have created minimal example here https://github.com/milandesai47/com.jms.test/blob/master/pom.xml#L33

Am I missing anything obvious in terms of spring dependencies?

Milan Desai
  • 1,228
  • 8
  • 23

1 Answers1

1

You need to add the following dependency to your pom.xml:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>5.0.0.RELEASE</version>
</dependency>
pringi
  • 3,987
  • 5
  • 35
  • 45
  • thanks @pringi, do you think it's a bug in spring framework 5.X shouldn't this be resolved transitively? – Milan Desai Mar 11 '22 at 08:49
  • 1
    It is not a bug. If you check spring-jms pom, you will see that spring-context has optional tag with value true. Probably spring-jms only needs this dependency to certain features, and in your case you are using one of those features. See https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html to understand better the optional tag. The most important point is: "If a user wants to use functionality related to an optional dependency, they have to redeclare that optional dependency in their own project". This is why transitivity will not fetch it. – pringi Mar 11 '22 at 09:30