1

I am getting following error in my weblogic console when i am starting my server.

SEVERE: Missing dependency for constructor public com.test.mine.exception.JsonExceptionMapper(java.lang.String,com.fasterxml.jackson.core.JsonLocation) at parameter index 0 SEVERE: Missing dependency for constructor public com.test.mine.exception.JsonExceptionMapper(java.lang.String,com.fasterxml.jackson.core.JsonLocation) at parameter index 1

Below is my java code.

package com.test.mine.exception;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParseException;

@Provider
@Service
public class JsonExceptionMapper extends JsonParseException implements ExceptionMapper {

    public JsonExceptionMapper(String msg, JsonLocation loc) {
        super(msg, loc);
        // TODO Auto-generated constructor stub
    }

    private static final Logger LOGGER = LoggerFactory.getLogger(JsonExceptionMapper.class);

    protected Logger getLogger() {
        return LOGGER;
    }

    public Status getStatus(JsonParseException thr) {
        return Status.BAD_REQUEST;
    }

    @Override
    public Response toResponse(Throwable arg0) {
        // TODO Auto-generated method stub
        return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).build();   
    }
}

2 Answers2

0

The annotation @Service tells spring to create a singleton of the annotated class. At startup spring tries to create that instance and to provide the required constructor args String msg, JsonLocation loc which it does not find, so the exception.

JsonExceptionMapper does not look like a service, and it should not be a singleton. Instead it must be created whenever an exception is created. I have never worked with that class, so sorry, cannot give you any advice on how to do that.

0

I bumped into a similar problem while configuring swagger to work with Jersey. After searching various forums found that Jersey scanning require a constructor without parameters. I added a a constructor and it worked for me.

pharsfalvi
  • 787
  • 1
  • 8
  • 12