4

我有一个非常有名的错误,但我无法解决它。我正在尝试为我的应用程序运行 arqullian 测试。我已经按照官方文档做了一切。长期寻找解决问题的方法一无所获。

 16:49:42,713 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."test.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Sender] with qualifiers [@Default] at injection point [[field] @Inject com.test.test2.ejb.AppManagerBean.sender]
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_13]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_13]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_13]
Caused by: org.jboss.weld.exceptions.DeploymentException: 

    WELD-001408 Unsatisfied dependencies for type [Sender] with qualifiers [@Default] 

    at injection point [[field] @Inject com.test.test2.ejb.AppManagerBean.sender]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
    ... 5 more

我的测试课:

package com.highstreetlabs.wlcome.rest;

import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.test.test2.ejb.AppManager;
import com.test.test2.ejb.Storage;
import com.test.test2model.Customer;
import com.test.test2.rest.model.ProximityModel;
import com.test.test2.util.EntityManagerProducer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.json.simple.parser.ParseException;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.ejb.EJB;
import javax.inject.Inject;

@RunWith(Arquillian.class)
public class CustomerCollectionResourceTest {

    @Deployment
    public static WebArchive createTestArchive() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
                .addClasses(CustomerCollectionResource.class, EntityManagerProducer.class,
                        AppManager.class, Storage.class,
                        ParseException.class, Sender.class)
                .addPackage(Customer.class.getPackage())
                .addPackage(Result.class.getPackage())
                .addPackage(NotFoundException.class.getPackage())
                .addPackage(CustomerPhotoResource.class.getPackage())
                .addPackage(ProximityModel.class.getPackage())
                .addAsResource("import.sql")
                .addAsManifestResource(EmptyAsset.INSTANCE, "META-INF/beans.xml")
                .addAsManifestResource("test-ds.xml", "test-ds.xml");
    }

    @Inject
    CustomerCollectionResource resource;
    @EJB
    AppManager manager;

    @Test
    public void testList() throws Exception {
        resource = new CustomerCollectionResource();
        resource.list(null);
    }
}

AppManagerBean.java

import com.google.android.gcm.server.Constants;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.google.common.base.Strings;
import com.test.test2.json.JacksonObjectMapperProvider;
import com.test.test2.model.*;
import com.test.test2.rest.HttpStatusException;
import com.test.test2.rest.NotFoundException;
import com.test.test2.rest.model.ProximityModel;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ejb.Asynchronous;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.*;
import javax.persistence.criteria.*;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.List;


/**
 * Stateless EJB bean containing entire business logic implementation
 */
@Local(AppManager.class)
@Stateless
public class AppManagerBean implements AppManager {

    public static final String
            GCM_ENTER_ACTION = "enter",
            GCM_EXIT_ACTION = "exit",
            PARAM_DATA_JSON = "proximityModel",
            PARAM_CUSTOMER_ID = "customerId",
            PARAM_ACTION = "action";

    @Inject
    EntityManager em;

    @Inject
    Sender sender;
....
}

最后是测试 CustomerCollectionResource 的类

@Path("customer/")
@RequestScoped
public class CustomerCollectionResource {

    final static int CACHEABLE_SECONDS = 0;
    @EJB
    private AppManager manager;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response list(@QueryParam("email") String email) {

        final List<Customer> entities = manager.listCustomers(email);

        if(entities.size() == 0)
            throw new NotFoundException("There is no any customer");

        ListModel<ListItem> result = new ListModel<ListItem>(entities.size());
        result.itemType = ListItem.MEDIA_TYPE;
        final UriBuilder itemLink = UriBuilder.fromResource(CustomerResource.class);
        for (Customer entity : entities) {
            result.add(new ListItem(entity.getName(), itemLink.build(entity.getId())));
        }
        CacheControl cc = new CacheControl();
        cc.setMaxAge(CACHEABLE_SECONDS);
        cc.setPrivate(true);
        return Response.ok(result).cacheControl(cc).build();
    }


}

发件人制作人

public class GcmSenderProducer {

    @Resource String senderId;

    @Produces public Sender getSender() {
        return new Sender(senderId);
    }

}
4

1 回答 1

3

是的,我还认为 GcmSenderProducer 丢失了,因此无法正确注入 Sender 类,因为它看起来没有无参数构造函数,我猜是构造函数。

于 2014-03-27T08:37:55.567 回答