1 Reply Latest reply on Jul 9, 2013 2:05 PM by Bradford Hovinen

    Injected resource is null in JAX-RS bean

    Bradford Hovinen Newbie

      Hello all,


      I'm trying to inject a resource into a JAX-RS bean and the injected resource is always null. During deploy no error is reported.


      The source for the JAX-RS bean is:




      public class DistanceService {


                private DistanceRepository repository;


                /* (non-Javadoc)

                 * @see com.dpdhl.cac.erc.services.IDistance#getDrivenDistance(java.lang.String, java.lang.String, java.lang.String, java.lang.String)



        public DistanceResult getDrivenDistanceXML(

                                              @QueryParam(value="origCountry") String origCountry,

                   @QueryParam(value="origPostalCode") String origPostalCode,

                                               @QueryParam(value="destCountry") String destCountry,

                                               @QueryParam(value="destPostalCode") String destPostalCode) {


            // NullPointerException here because repository is always null

            return repository.getDrivenDistance(origCountry, origPostalCode, destCountry, destPostalCode);




      The service to be injected is:



      public class DistanceRepository {


                private EntityManager em;


                public DistanceResult getDrivenDistance(String origCountry, String origPostalCode, String destCountry, String destPostalCode) {...}



      The application-class is defined as follows:


      public class ERCApplication extends Application {

                private Set<Class<?>> classes = new HashSet<>();

                private Set<Object> singletons = new HashSet<>();


                public ERCApplication() {

          singletons.add(new DistanceService());




                public Set<Object> getSingletons() {

          return singletons;




                public Set<Class<?>> getClasses() {

          return classes;




      I've tried various combinations of annotations to no avail. I can confirm, however, that the @Inject annotation is not being ignored, since some of my attempts caused Weld to complain during deploy.


      Can anyone help? Thank you in advance.