1

I need inject my EJB service into Spring-WS Endpoint:

@Stateless
public class MeteringPointService {

    private static final int LIMIT = 100;

    public Integer getResponseStatus() {
        return new Random().nextInt(LIMIT);
    }
}


@Endpoint
public class CreateMeteringPointEndpoint {

    private MeteringPointService meteringPointService;

    @PayloadRoot(localPart = "CreateMeteringPointRequest", namespace = "...")
    @ResponsePayload
    public CreateMeteringPointResponse handleRequest(@RequestPayload CreateMeteringPointRequest request) {

        CreateMeteringPointResponse response = new CreateMeteringPointResponse();
        Integer status = meteringPointService.getResponseStatus();
        response.setResponseStatus(status);
        return response;
    }

    public MeteringPointService getMeteringPointService() {
        return meteringPointService;
    }

    public void setMeteringPointService(MeteringPointService meteringPointService) {
        this.meteringPointService = meteringPointService;
    }
}

I tried Spring

    <jee:local-slsb id="meteringPointService" jndi-name="ejb/meteringPointService"
                business-interface="service.impl.MeteringPointService"/>

    <bean id="createMeteringPointEndpoint" class="ws.endpoint.CreateMeteringPointEndpoint">
        <property name="meteringPointService" ref="meteringPointService"/>
    </bean>

I tried @EJB(mappedName="") StackOverflow, RedHat

And also tried CDI @Inject from Java EE6 StackOverflow

...but nothing works. Can you help me? GlassFish 4.

I'm still getting errors during deployment like:

remote failure: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleExc
eption: org.apache.catalina.LifecycleException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.impl.MeteringPointService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.facto
ry.annotation.Autowired(required=true)}. Please see server.log for more details.
Command deploy failed.

remote failure: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleExc
eption: org.apache.catalina.LifecycleException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.impl.MeteringPointService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}. Please
see server.log for more details.
Command deploy failed.
Community
  • 1
  • 1
sasynkamil
  • 859
  • 2
  • 12
  • 23
  • 1
    `@Autowire` and `@Inject` require the bean to be available in the context. That obviously isn't the case. `@Ejb` should be able to do the lookup IF you specify the name correctly (also make sure that you have an entry in your web.xml to reference to EJB). Also what failed with the namespace (`` ) lookup? That should just work... – M. Deinum Dec 05 '13 at 07:30
  • @M.Deinum What do you mean by reference to EJB in web.xml? It should not work just with anotation [code](@EJB private MeteringPointService meteringPointService;) ? – sasynkamil Dec 05 '13 at 08:41
  • You need to define your jndi resources in your web.xml (to make them available). What did you try when using @EJB? Have you used the fully qualified JNDI name? The namespace does a lookup in `java:comp/env` by default and that is not a well-known location for EJB (if I'm not mistaken). – M. Deinum Dec 05 '13 at 08:44
  • @M.Denium I just used Stateless anotation on the service class name and anotation EJB on the property where I need inject it. I didn't specified JNDI name at all, I think that it should work automatically. A least it worsk if I use just EJB (not Spring) – sasynkamil Dec 05 '13 at 08:49
  • 1
    Correct but Spring isn't the normal CDI and spring will only inject beans from the context (or which it can lookup). When you specify an EJB it will create a couple of JNDI names/entries for that EJB (they are specified in the EJB spec) which you can/must use to do a lookup. But as mentioned what have you tried (show some code you, you specified a mapped name but what/how/where). – M. Deinum Dec 05 '13 at 08:53
  • @M.Deinum I jused annotatation EJB(mappedName="ejb/MeteringPointService") – sasynkamil Dec 05 '13 at 08:58
  • I used: `jndi-name="java:global/psl-ws-mock2-trunk-SNAPSHOT/MeteringPointServiceImpl"` and now it works. Thx – sasynkamil Dec 05 '13 at 13:52
  • There should also be a more readable name if I'm not mistaken. Something like `java:module/MeteringPointServiceImpl!your.package.to.interface.MeteringPointService` if you don't have an interface replace with the FQCN. See http://jaitechwriteups.blogspot.nl/2010/10/ejb31-global-jndi-access-portable-jndi.html – M. Deinum Dec 05 '13 at 14:02

0 Answers0