I have an application example with a service:

RestApp.java

```
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/webapi")
public class RestApp extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<>();
        classes.add(MessageService.class);
        return classes;
    }
}

```

MessageService.java

```
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.List;

@Stateless
@Path("/messages")
public class MessageService {

    @Inject
    private MessagesManager messagesManager;

    @GET
    @Path("all")
    @Produces({MediaType.APPLICATION_JSON})
    public List<Message> getMessages() {
        return messagesManager.getMessages();
    }
}

```

and the service depends on the singleton MessagesManager.java:

```
import javax.ejb.*;
import javax.inject.Singleton;

@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class MessagesManager implements Serializable {

    private List<Message> messages = new ArrayList<>();

    @Lock(LockType.READ)
    public List<Message> getMessages() {
        messages.add(new Message(1, "message text"));
        return messages;
    }
}

```

and this app works fine. But during the test occurs error of injection:

> 
> org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=MessagesManager,parent=MessageService,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1232089028)
> 
> 
> 

Test code is:

```
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
import static org.junit.Assert.assertEquals;

public class RestAppTest extends JerseyTest {

    @Override
    protected Application configure() {
        return new ResourceConfig(MessageService.class);
    }

    @Test
    public void testGet() {
        final Response response = target("messages/all").request().get();
        assertEquals(200, response.getStatus());
    }
}

```

Why it happens and how to fix it?