Skip to main content

Issue with @Inject and @WebService

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
emailnbw
Offline
Joined: 2008-05-28

From things I've read, including Arun's blog [1], it looks like I should be able to use @Inject with a @WebService annotated class but it is not working for me, though injection of this bean does work in other classes (eg. @RequestScoped JAX-RS/Jersey resource classes).

The bean I am trying to inject into my jax-ws/metro class is an @ApplicationScoped CDI bean. Arun's blog uses a @RequestScoped bean. My setup looks something like this:

@WebService(serviceName = "FooService")
public class FooService {

@Inject
BarBean myBarBean;

...
}

@ApplicationScoped
public class BarBean implements Serializable {

..

@PostConstruct
public void afterCreate() {

do stuff
}

..

}

myBarBean is always NULL. This is under GF 3.1.2 b23. Thoughts?

-Noah

[1] - https://blogs.oracle.com/arungupta/entry/totd_124_using_cdi_jpa

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
emailnbw
Offline
Joined: 2008-05-28

Please disregard. I discovered some shenanigans with how this web service was being invoked to begin with. Hint, 'new' was involved.

-Noah

On Jan 31, 2013, at 4:03 PM, Noah White wrote:

>
> From things I've read, including Arun's blog [1], it looks like I should be able to use @Inject with a @WebService annotated class but it is not working for me, though injection of this bean does work in other classes (eg. @RequestScoped JAX-RS/Jersey resource classes).
>
> The bean I am trying to inject into my jax-ws/metro class is an @ApplicationScoped CDI bean. Arun's blog uses a @RequestScoped bean. My setup looks something like this:
>
> @WebService(serviceName = "FooService")
> public class FooService {
>
> @Inject
> BarBean myBarBean;
>
> ...
> }
>
> @ApplicationScoped
> public class BarBean implements Serializable {
>
> ..
>
> @PostConstruct
> public void afterCreate() {
>
> do stuff
> }
>
> ..
>
> }
>
>
> myBarBean is always NULL. This is under GF 3.1.2 b23. Thoughts?
>
> -Noah
>
> [1] - https://blogs.oracle.com/arungupta/entry/totd_124_using_cdi_jpa