Search code examples
javaspring-bootazureazure-storage

Azure + SpringBoot 'com/fasterxml/jackson/core/JsonFactory'


I'm getting started with Java + SprintBoot + AzureStorage. I just created a project thru Spring initializer using the following configuration:

spring project config

I'm trying to create a simple rest method to return the list of shares from Azure, but i'm getting the following error:

Exception Details:
  Location:
    com/fasterxml/jackson/databind/cfg/MapperBuilder.streamFactory()Lcom/fasterxml/jackson/core/TokenStreamFactory; @7: areturn
  Reason:
    Type 'com/fasterxml/jackson/core/JsonFactory' (current frame, stack[0]) is not assignable to 'com/fasterxml/jackson/core/TokenStreamFactory' (from method signature)
  Current Frame:
    bci: @7
    flags: { }
    locals: { 'com/fasterxml/jackson/databind/cfg/MapperBuilder' }
    stack: { 'com/fasterxml/jackson/core/JsonFactory' }

Nothing special in my code to get shares as far as i can see:

AzureStoreService

@Service
public class AzureStorageService {

    @Value("${azure.storage.accountName}")
    private String accountName;

    @Value("${azure.storage.accountKey}")
    private String token;

    private ShareServiceClient createServiceClient() {
        String shareURL = String.format("https://%s.file.core.windows.net", accountName);
        return new ShareServiceClientBuilder().endpoint(shareURL).sasToken(token).buildClient();
    }

    public List<String> listShares() {
        List<String> shares = new ArrayList<>(0);
        ShareServiceClient client = createServiceClient();
        client.listShares().forEach(item -> shares.add(item.getName()));
        return shares;
    }
}

AzureController

@RestController
@RequestMapping("/storage")
public class AzureController {

    @Autowired
    private AzureStorageService azureStorageService;

    @GetMapping("/list-shares")
    private ResponseEntity<List<String>> listShares() {
        List<String> shares = azureStorageService.listShares();
        return new ResponseEntity<>(shares, HttpStatus.OK);
    }
}

I guess the problem is related to library version conflicts between Spring Boot and Azure, but which one should I keep and how.

You probably faced this issue before, any hint / suggestion is welcome.

Thanks a lot in advance!


Solution

  • I finally found the root cause for this problem:

    One important thing that I forgot to mention is that I'm using JBoss to deploy the application, and is here the the problem comes from, becasue of the modules that JBoss includes. So I just needed to add a deployment estructure file.

    jboss-deployment-estructure.xml:

    <?xml version='1.0' encoding='UTF-8'?>
    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
        <deployment>
            <module-alias name="deployment.AzureTestWS"/>
            <exclusions>
                <module name="com.fasterxml.jackson.core.jackson-core"/>
                <module name="com.fasterxml.jackson.core.jackson-databind"/>
                <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider"/>
                <module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
                <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310"/>
                <module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" />
            </exclusions>
        </deployment>
    </jboss-deployment-structure>
    

    this worked for mi on JBoss EAP 7.2