dev@glassfish.java.net

Re: A question about _at_Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)

From: Tang Yong <tangyong_at_cn.fujitsu.com>
Date: Mon, 13 May 2013 23:18:11 +0900

Hi Tom,

Great reply! Test has passed by copying decorate method.

Thanks
--Tang

Tom Mueller wrote:
> Hi Tang.
>
> In order to have the @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)
> work, you need to use the
> com.sun.enterprise.configapi.tests.ConfigApiTest in the
> nucleus/admin/config-api module. This class has a decorate method that
> creates the necessary index entries. Or, copy the decorate method into
> your ATest class.
>
> Tom
>
>
> On 5/13/13 6:48 AM, Tang Yong wrote:
>> Tom, JWells,
>>
>> I have a question about @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)
>> as following,
>>
>> [Background]
>> Assuming that I have a bundle called "AImpl" which implements AEx interface,
>>
>> @Contract
>> public interface AEx {
>> ...
>> }
>>
>> @Service
>> public class AImpl implements AEx {
>> ...
>> @Inject
>> @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)
>> private Config config;
>> ...
>> }
>>
>> Then, I create a test for AImpl class which extends
>> org.glassfish.tests.utils.ConfigApiTest and uses
>> org.glassfish.tests.utils.Utils to obtain serviceLocator,
>>
>> public class ATest extends ConfigApiTest {
>> ServiceLocator serviceLocator = getHabitat();
>> AEx a = serviceLocator.getService(AEx.class);
>> ...
>> }
>>
>> Then, while running the test, I got the following exception,
>>
>> org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no
>> object available for injection at
>> Injectee(requiredType=Config,parent=AImpl,qualifiers={_at_javax.inject.Named(value=default-instance-name)}),
>> position=-1,optional=false,self=false,unqualified=null,9684505)
>>
>> Then, I made some investigation and found that once I removed
>> @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME), test will pass.
>>
>> Because @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME) is a normal
>> writing in glassfish admin related comp, So, I have the following
>> requestions:
>>
>> 1) there is any difference between placing
>> @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME) and removing the annotation?
>>
>> 2) while using @Named as a qualifier, and using
>> org.glassfish.tests.utils.Utils to initialize HK2 ServiceLocator env,
>> the issue will happen. So, I doubted whether having some issue in Utils
>> class. And I also made a confirmation that backing HK2 Habitat age, eg.
>> Glassfish 4.0-b36, the exception can not happen.
>>
>> In addition, My background comes from
>> org.glassfish.paas.tenantmanager.impl.TenantManagerImpl class and its
>> dev test while I am trying to bring paas back trunk.
>>
>> Pl. forgiving long text, because the issue makes me a litter puzzle.
>>
>> Thanks
>> --Tang
>>
>
>
>

-- 
−−−−−−−−−−−−−−−−−−−−−−
Tang Yong
Senior Engineer
Glassfish Team Developer(OSGi&OSGi-JavaEE)
OSGi Alliance Supporter
Blog: http://osgizone.typepad.com/tangyong/
Nanjing Fujitsu NanDa Software Tec CO.,LTD
http://www.fujitsu.com/cn/fnst
Tel: +86-25-86630566-8310
Fax: +86-25-83317685              
−−−−−−−−−−−−−−−−−−−−−−