users@glassfish.java.net

Re: CDI with JAX-RS null injection

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 28 Jul 2010 09:54:46 +0200

Hi,

You need to add a CDI scope annotation such as @RequestScoped.

It is necessary to explicitly opt in because CDI subtly changes the
JAX-RS programming model, which could break existing JAX-RS code.

We are considering an option for default CDI management (with an
servlet/filter) init param, but that requires more involved
integration with the CDI extension mechanism.

Paul.

On Jul 21, 2010, at 2:19 AM, glassfish_at_javadesktop.org wrote:

> I have this code that has a injected element that is always null. Is
> this a bug?
>
> I'm using the final version of glassfish 3.0.1
>
> Clients.java
> @Path("clients")
> public class Clients {
> @Inject private Mail mail;
>
> @GET
> @Produces("application/xml")
> public String getXml() {
> return "hello world";
> }
>
> @PostConstruct
> void test() {
> System.out.println("Clients.test()");
> }
> }
>
> Mail.java
> public class Mail {
> }
>
> web.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app id="WebApp_ID" version="3.0"
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
> ">
> <display-name>jaxrs</display-name>
> <servlet>
> <servlet-name>Jersey</servlet-name>
> <servlet-
> class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-
> class>
> </servlet>
> <servlet-mapping>
> <servlet-name>Jersey</servlet-name>
> <url-pattern>/portal/*</url-pattern>
> </servlet-mapping>
> <welcome-file-list>
> <welcome-file>index.html</welcome-file>
> </welcome-file-list>
> </web-app>
>
> beans.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd
> ">
> </beans>
> [b][/b][b][/b]
> [Message sent by forum member 'fsousa']
>
> http://forums.java.net/jive/thread.jspa?messageID=478160
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>