0

My project is a Web Dynamic Project I am using JSF 2.2 with CDI in tomcat 7.0. The CDI is working well for my beans, but when I try to use the @Injectfor my Web Service class it is returning null.

@Named
public class SchoolDataWS {
    @Inject
    private SchoolDataDAO dao;

    public SchoolDataWS() {
        System.out.println(dao);
    }

    public String save(String json) {
        String result = (dao != null ? dao.toString() : "null");
        return result;
    }
}

To generate the WSDL I am using the Eclipse resource new -> other -> Web Service. The Service Implementation is set to Start service and the Client type is set to No client. I am setting Style and use to document/literal.

I have the the WebContent/WEB-INF/bean.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>

I have the WebContent/META-INF/context.xml empty

My pom.xml is this:

    <!-- CDI -->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-core</artifactId>
        <version>2.2.14.Final</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.2.14.Final</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se-core</artifactId>
        <version>2.2.14.Final</version>
    </dependency>

    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jandex</artifactId>
        <version>1.2.2.Final</version>
    </dependency>
Kukeltje
  • 11,924
  • 4
  • 19
  • 44
  • Your question is genuinely confusing. JSF is not a web service framework. It's a HTML form based MVC framework. I'm nowhere seeing web service specific code. That class is a CDI managed bean (which could in turn be used in a JSF page, or injected in any container managed artifact), not a web service controller. Java EE offers JAX-WS and JAX-RS as web service APIs. Which one exactly are you using? – BalusC Jul 22 '15 at 21:25
  • Sorry being confusing cause I am kind noob, I am using the Apache Axis to generate the web services. Basically my doubt was if I could use the @Inject annotation on web services calls, but trying a lot yesterday, I just quit and started to create my DAOs and EntityManager using "new". I believe the CDI just works on HTML pages, I thought I could use it, cause the web services are nested on Apache Tomcat. – Rodrigo Sordi Jul 23 '15 at 13:37
  • Tomcat indeed doesn't support CDI out the box. You'd have to manually install and configure it. Detailed instructions can be found in this possible duplicate: http://stackoverflow.com/questions/18995951/how-to-install-and-use-cdi-on-tomcat – BalusC Jul 23 '15 at 13:51

0 Answers0