REST + CDI (dependency error)

Asked

Viewed 261 times

1

Hello, people, I come for some help, because it is my first contact with CDI and he does not find my resources. I will post the classes involving the Annotations, injects and console errors. I hope you will guide me!

Those are the mistakes.

12:08:32,870 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 61) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./softbox: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./softbox: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:224)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
... 6 more
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
at org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory.getScannableClass(JndiResourceFactory.java:62)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:168)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:156)
at org.jboss.resteasy.core.ResourceMethodRegistry.addJndiResource(ResourceMethodRegistry.java:123)
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:383)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:241)
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:195)
... 8 more
Caused by: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
at javax.naming.InitialContext.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory.getScannableClass(JndiResourceFactory.java:57)
... 16 more

12:08:32,878 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "softbox.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./softbox" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./softbox: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local
Caused by: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local"}}
12:08:32,950 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "test2.war" (runtime-name : "test2.war")
12:08:32,951 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "softbox.war" (runtime-name : "softbox.war")
12:08:32,964 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./softbox: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./softbox: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: CategoriaResource/local -- service jboss.naming.context.java.CategoriaResource.local

12:08:33,264 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
12:08:33,271 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
12:08:33,271 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 9.0.1.Final (WildFly Core 1.0.1.Final) started (with errors) in 10801ms - Started 370 of 559 services (2 services failed or missing dependencies, 232 services are lazy, passive or on-demand)
12:08:33,448 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0010: Stopping weld service for deployment softbox.war
12:08:33,574 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0028: Stopped deployment softbox.war (runtime-name: softbox.war) in 209ms
12:08:33,696 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0009: Undeployed "softbox.war" (runtime-name: "softbox.war")
12:08:33,698 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
WFLYCTL0184:    New missing/unsatisfied dependencies:
  service jboss.deployment.unit."softbox.war".component."com.sun.faces.config.ConfigureListener".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."javax.faces.webapp.FacetTag".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."org.jboss.weld.servlet.WeldInitialListener".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.deployment.unit."softbox.war".component."org.jboss.weld.servlet.WeldTerminalListener".START (missing) dependents: [service jboss.deployment.unit."softbox.war".deploymentCompleteService] 
  service jboss.undertow.deployment.default-server.default-host./softbox (missing) dependents: [service     jboss.deployment.unit."softbox.war".deploymentCompleteService] 
WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./softbox

This is the DAO

    package softbox.dao;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;

    import javax.enterprise.context.RequestScoped;

    import softbox.dto.Categoria;
    @RequestScoped
    public class CategoriaDao {

public static ArrayList<Categoria> getCategorias(Connection con) throws SQLException {
    ArrayList<Categoria> categoriaList = new ArrayList<Categoria>();
    PreparedStatement stmt = con.prepareStatement("SELECT * FROM categoria ORDER BY nom_categoria");
    ResultSet rs = stmt.executeQuery();
    try {
        while (rs.next()) {
            Categoria categoriaObj = new Categoria();
            categoriaObj.setId(rs.getInt("id"));
            categoriaObj.setNom_categoria(rs.getString("nom_categoria"));
            categoriaList.add(categoriaObj);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return categoriaList;
}

public static Categoria getCategoria(Connection con, int id) throws SQLException{
    String sql = "SELECT * FROM categoria WHERE id = ? ";
    PreparedStatement stmt = con.prepareStatement(sql);
    stmt.setInt(1, id);
    ResultSet rs = stmt.executeQuery();
    rs.first();
    Categoria categoriaObj = new Categoria();
    categoriaObj.setId(rs.getInt("id"));
    categoriaObj.setNom_categoria(rs.getString("nom_categoria"));
    return categoriaObj;
}

public static void insereCategoria(Connection con, Categoria c) throws SQLException {

    String sql = "INSERT INTO categoria(nom_categoria) VALUES (?)";
    PreparedStatement stmt = con.prepareStatement(sql);
    stmt.setString(1, c.getNom_categoria());
    stmt.execute();
    stmt.close();
}

public static void apagaCategoria(Connection con, int id) throws Exception {
    String sql = "DELETE FROM categoria WHERE id = ?";
    PreparedStatement stmt = con.prepareStatement(sql);
    stmt.setInt(1, id);
    stmt.execute();
}

public static void atualizaCategoria(Connection con, int id,  Categoria c) throws Exception {
    String sql = "UPDATE Categoria SET nom_categoria = ? where id = ?";
    PreparedStatement stmt = con.prepareStatement(sql);
    stmt.setString(1, c.getNom_categoria());
    stmt.setInt(2, c.getId());
    stmt.execute();
}
    }

This is one of the resources

    package softbox.resources;

    import java.sql.Connection;

    import javax.faces.bean.SessionScoped;
    import javax.inject.Inject;
    import javax.inject.Named;
    import javax.ws.rs.DELETE;
    import javax.ws.rs.GET;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.Context;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Request;
    import javax.ws.rs.core.UriInfo;

    import softbox.dto.Categoria;
    import softbox.dao.CategoriaDao;
    import softbox.dao.Database;

    @SessionScoped
    @Named("CategoriaResource")
    public class CategoriaResource {
@Context
UriInfo uriInfo;
@Context
Request request;
int id;

@Inject
private CategoriaDao dao;

public CategoriaResource(UriInfo uriInfo, Request request, int id) {
    this.uriInfo = uriInfo;
    this.request = request;
    this.id = id;
}

@GET
// @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public Categoria getCategoria() throws Exception {
    Database db = new Database();
    Connection con = db.getConnection();
    Categoria c = dao.getCategoria(con, id);
    return c;
}

@DELETE
public void apagaCategoria() throws Exception {
    Database db = new Database();
    Connection con = db.getConnection();
    dao.apagaCategoria(con, id);
}
}

This is the other resource.

package softbox.resources;

import java.sql.Connection;

import java.util.List;

import javax.faces.bean.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import softbox.dao.CategoriaDao;
import softbox.dto.*;
import softbox.dao.Database;
@SessionScoped
@Named("CategoriasResource")
@Path("/categorias")
public class CategoriasResource {
@Context
UriInfo uriInfo;
@Context
Request request;

@Inject 
private CategoriaDao dao;

@GET
//@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON })
public List<Categoria> categorias() throws Exception {
    Database db = new Database();
    Connection con = db.getConnection();
    List<Categoria> categoriaList = dao.getCategorias(con);
    return categoriaList;
}

@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void insereCategoria(@QueryParam("nom_categoria") String nom_categoria,
        @Context HttpServletResponse servletResponse) throws Exception {
    Categoria c = new Categoria();
    c.setNom_categoria(nom_categoria);
    Database db = new Database();
    Connection con = db.getConnection();
    dao.insereCategoria(con, c);

    // servletResponse.sendRedirect("../edit_todo.html");
}

@PUT
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void atualizaEndereco(@QueryParam("id") int id , @QueryParam("nom_categoria") String nom_categoria,
        @Context HttpServletResponse servletResponse) throws Exception {
    Categoria x = new Categoria(id, nom_categoria);
    Database db = new Database();
    Connection con = db.getConnection();
    dao.atualizaCategoria(con, id, x);
}

@Path("{categoria}")
public CategoriaResource getCategoria(@PathParam("id") int id) throws Exception {
    return new CategoriaResource(uriInfo, request, id);

}
}

This is web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>softbox.primeiro</display-name>

<context-param>
     <param-name>resteasy.use.builtin.providers</param-name>
     <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>resteasy.jndi.resources</param-name>
    <param-value>CategoriaResource/local, CategoriasResource/local</param-value>
</context-param>
<context-param>
     <param-name>resteasy.servlet.mapping.prefix</param-name>
     <param-value>/rest</param-value>
</context-param>

 <listener>
  <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>

 <servlet>
  <servlet-name>resteasy-servlet</servlet-name>
  <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
 <servlet-mapping>
  <servlet-name>resteasy-servlet</servlet-name>
   <url-pattern>/rest*/</url-pattern>
 </servlet-mapping>

</web-app>

This is the Beans.xml

<?xml version="1.0"?>
<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://jboss.org/schema/cdi/beans_1_0.xsd"/>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.