2

I am attempting to run a Google Calendar Java sample within my Spring boot application. The Google Calendar sample runs as expected when run in isolation, but one of it's dependancies conflicts with a Spring boot dependancy when they are run together.

In this case I have the following dependancies enabled: gradle dependancies enabled

and see the following error when launching Spring boot:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoSuchMethodError: javax.servlet.ServletContext.addServlet

I can get Spring boot to run making the following dependancy changes and commenting the Google Calendar code that requires

import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;

gradle dependancies disabled

Of course, this means the Google Calendar sample won't run anymore...

I think what I need is some way of force targeting specific versions of a dependancy so Spring boot can find the method it's currently missing while allowing the Google Calendar sample to import what it needs, but being new to Spring boot I'd appreciate any help or suggestions.

Thanks for your time :)

1
  • you can always declare a dependency yourself with a fixed version number, it will take precedence to other transitive dependencies (in Maven this is done with dependencyManagement. not sure how to do that in graddle)
    – spi
    Jan 19, 2018 at 11:50

3 Answers 3

1

I had the same problem with com.google.api-client in my gradle (also in spring boot app). The problem seems to be connected with servlet version provided by google. I fixed it by adding exclusion in build.gradle compile line:


    compile (group: 'com.google.api-client', name: 'google-api-client-appengine', version: '1.23.0'){
    exclude group:'javax.servlet'
    }
1

I agree with Albert Mosialek. In my case I was using maven and I had to insert the following:

<dependency>
    <groupId>com.google.oauth-client</groupId>
    <artifactId>google-oauth-client-jetty</artifactId>
    <version>${project.oauth.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>servlet-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>
1

Add below line into file build.gradle

compile'javax.servlet:javax.servlet-api:3.1.0'

I try and run ok.

Hope helpfull with you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.