Jaap,
In the code I posted, there was not constructor.  I moved the injection of 
personService to an @Reference annotated field.  The @Activator annotation is 
for a method, which you may not need based on your example.

Paul Spencer


> On Jan 23, 2023, at 2:30 PM, Jaap Gordijn <[email protected]> wrote:
> 
> Hi Paul,
> 
> That constructor is called, but only if I disable @@JaxrsApplicationSelect.
> 
> If I enable it, only the default constructor is called (Rest() in my case.
> And no DS.
> 
> -- Jaap
> 
>> -----Original Message-----
>> From: Paul Spencer <[email protected]>
>> Sent: maandag 23 januari 2023 18:59
>> To: [email protected]
>> Subject: Re: aries-jax-rs-whiteboard with @JaxrsApplicationSelect works not
>> with DS
>> 
>> Jaap,
>> Your @Activate annotation is incorrect.
>> Try the following.
>> 
>> 
>> …
>> public class Rest() {
>> 
>>    @Reference
>>    private PersonService personService;
>> 
>>    @Activate
>>    public void activate(Map <String,?> properties) {
>>    ...
>>    }
>> 
>> }
>> 
>> Paul Spencer
>> 
>> 
>>> On Jan 23, 2023, at 12:40 PM, Jaap Gordijn <[email protected]> wrote:
>>> 
>>> Hi,
>>> 
>>> I use an Application object (with @JaxrsApplicationSelect), injection
>>> via DS does not work:
>>> 
>>> @Component(service = Rest.class, scope = ServiceScope.PROTOTYPE)
>>> @JaxrsResource @JaxrsApplicationSelect("(" +
>>> JaxrsWhiteboardConstants.JAX_RS_NAME +
>>> "=MyApplication)")
>>> @JSONRequired
>>> @Produces(MediaType.APPLICATION_JSON)
>>> public class Rest {
>>> 
>>>  private PersonService personService;
>>> 
>>>  /*
>>>   public Rest() {
>>> System.out.println("Constructing REST");
>>>    this.personService = new PersonServiceImpl();
>>>    }
>>>  */
>>> 
>>>   @Activate
>>>   public Rest(final @Reference PersonService personService) {
>>> System.out.println("Constructing REST");
>>>    this.personService = personService;
>>>   }
>>> 
>>>   @GET
>>>   @Path("/person")
>>>   public List<PersonDto> listPersons() {
>>>     return personService.select();
>>>  }
>>> 
>>>  @GET
>>>  @Path("/test")
>>>  public String test() {
>>>    return "test";
>>>  }
>>> }
>>> 
>>> The @Activate constructor is not called. If I enable the Rest()
>>> constructor that one is called.
>>> if I disable @JaxrsApplicationSelect, the personService is injected.
>>> 
>>> It seems that once an Application class is used (see below), DS is not
>>> working.
>>> This leads to the question what I have to set up for the Application object:
>>> 
>>> @Component(service=Application.class, property =
>>> {"servlet.init.hide-service-list-page=true"} )
>>> @JaxrsApplicationBase("example")
>>> @JaxrsName("MyApplication")
>>> public class MyApplication extends Application {
>>> 
>>> public Set<Class<?>> getClasses() {
>>>     HashSet<Class<?>> set = new HashSet<Class<?>>();
>>>     set.add(Rest.class);
>>>     return set;
>>>  }
>>> 
>>> }
>>> 
>>> Jax-rs-whiteboard 2.02
>>> Karaf 4.4.3
>>> 
>>> Thanks,
>>> 
>>> -- Jaap
>>> 
>>> 
> 
> 

Reply via email to