WELD-001408: Dependencias insatisfechas para el tipo Cliente con calificadores @Predeterminado
Soy un Java EE-novato. Quiero probar JSF y por lo tanto hizo un programa simple, pero no puede desplegarlo. Recibo el siguiente mensaje de error:
cannot Deploy onlineshop-war
deploy is failing=Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private de.java2enterprise.onlineshop.RegisterController.customer
at de.java2enterprise.onlineshop.RegisterController.customer(RegisterController.java:0)
. Please see server.log for more details.
Mi código es el siguiente: Cliente.java:
package de.java2enterprise.onlineshop.model;
public class Customer {
private String email;
private String password;
}
RegisterController.java:
package de.java2enterprise.onlineshop;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject;
import de.java2enterprise.onlineshop.model.*;
@Named
@RequestScoped
public class RegisterController {
private static final long serialVersionUID = 1L;
@Inject
private Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String persist() {
return "/index.xhtml";
}
}
Para compilarlo tuve que incluir cdi-api.jar como biblioteca externa. ¿Hay alguien aquí que pueda ayudarme? Gracias a todos por adelantado.
4 answers
Su clase Customer
tiene que ser descubierta por CDI como un frijol. Para eso tienes dos opciones:
-
Ponga una anotación definitoria de frijol en él. Como
@Model
es un estereotipo, es por eso que funciona. Un calificador como@Named
no es una anotación definitoria de frijol, razón por la cual no funciona Cambie el modo de descubrimiento de bean en su archivo bean del valor predeterminado "anotado" a "todo" agregando un archivo
beans.xml
en su jar.
Tenga en cuenta ese @Named solo tiene un uso: exponer tu bean a la interfaz de usuario. Otros usos son para malas prácticas o compatibilidad con el marco heredado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-06 06:40:24
También es bueno asegurarse de que tiene la importación correcta
Tuve un problema como ese y descubrí que el frijol estaba usando
javax.faces.view.ViewScoped;
En lugar de
javax.faces.bean.ViewScoped;
Una sola palabra puede arruinar el mundo a veces... o simplemente arruinar mi día en este caso.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-04 18:34:26
Necesita anotar su clase de cliente con @Named o @ Model anotación:
package de.java2enterprise.onlineshop.model;
@Model
public class Customer {
private String email;
private String password;
}
O crear/modificar frijoles.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-05 19:48:43
Para inyectar un objeto, su clase debe ser conocida por el mecanismo CDI. Usualmente agregar la anotación @ Named hará el truco.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-05 19:46:35