简体   繁体   English

JSF-org.jboss.weld.exceptions.DeploymentException:WELD-001408:类型的依赖关系未满足

[英]JSF - org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type

Note: I have already tried the solutions available in similar question on SO. 注意:我已经尝试过类似问题的可用解决方案。

I am working on a simple CRUD application using JSF, Java 8, Tomcat 9, Maven, H2 db. 我正在使用JSF,Java 8,Tomcat 9,Maven,H2 db开发一个简单的CRUD应用程序。 When I am trying to start the server, following exception occurs 当我尝试启动服务器时,发生以下异常

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ContactsDAO with qualifiers @Default at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public com.contacts.ContactsController(ContactsDAO) 由以下原因引起:org.jboss.weld.exceptions.DeploymentException:WELD-001408:带有限定符@Default的类型ContactsDAO的依赖关系未满足,默认值在注入点[BackedAnnotatedParameter] [BackedAnnotatedConstructor]的参数1 @Inject public com.contacts.ContactsController(ContactsDAO)

When I remove @Inject annotation from the constructor of ContactsController, the exception is gone but the contactsDao is null hence I am unable to get the list of contacts. 当我从ContactsController的构造函数中删除@Inject批注时,异常消失了,但是contactsDao为空,因此我无法获取联系人列表。

ContactsController.java ContactsController.java

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named("contactsController")
@SessionScoped
public class ContactsController implements Serializable {
public ContactsController() {
    }

    @Inject
    public ContactsController(ContactsDAO contactDAO) {
        this.contactDAO = contactDAO;
    }
@PostConstruct
    public void init() {

        logger.info("retrieving list of contacts");

        try {
            if(contactDAO != null) {
                System.out.println("ifff");
                contacts = contactDAO.getAllContacts();
            }
            else {
                System.out.println("Contacts DAO null");
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

} }

ContactsDAO.java ContactsDAO.java

public interface ContactsDAO {
List<Contact> getAllContacts() throws SQLException;
}

ContactsDAOImpl.java ContactsDAOImpl.java

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@Named
@ApplicationScoped
public class ContactsDAOImpl implements ContactsDAO, Serializable{
@Override
    public List<Contact> getAllContacts() throws SQLException {
        List<Contact> contacts = new ArrayList<>();
        try {
            String sql = "SELECT * FROM contacts";
            connect();

            PreparedStatement pstmt = jdbcConnection.prepareStatement(sql);

            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                Contact newContact = new Contact(); 
                newContact.setId(rs.getInt("id"));

                contacts.add(newContact);
            }
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        return contacts;
    }
}

WEB-INF/beans.xml WEB-INF / beans.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="annotated">
</beans>

Tomcat does not support CDI. Tomcat不支持CDI。 Look at this post from @BalusC 看看@BalusC的这篇文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.jboss.weld.exceptions.DeploymentException:WELD-001408对类型的依赖关系未满足 - org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for Type DeploymentException:WELD-001408:带有限定符@Default的类型[]的不满意依赖项 - DeploymentException: WELD-001408: Unsatisfied dependencies for type [] with qualifiers @Default org.jboss.weld.exceptions.DeploymentException WELD-001409:带有限定符的类型X的不明确的依赖关系@Default - org.jboss.weld.exceptions.DeploymentException WELD-001409: Ambiguous dependencies for type X with qualifiers @Default Arquillian over Wildfly DeploymentException:WELD-001408:不满意的依赖关系 - Arquillian over Wildfly DeploymentException: WELD-001408: Unsatisfied dependencies WELD-001408类型[配置]的相关性未满足 - WELD-001408 Unsatisfied dependencies for type [Configuration] DeploymentException: WELD-001408: 不满意的类型依赖<Class>在注入点使用限定符 @Default [BackedAnnotatedField] - DeploymentException: WELD-001408: Unsatisfied dependencies for type <Class> with qualifiers @Default at injection point [BackedAnnotatedField] WELD-001408:带限定符@Default的ServiceLocator类型的依赖关系未满足 - WELD-001408: Unsatisfied dependencies for type ServiceLocator with qualifiers @Default WELD-001408类型的不满意依赖关系...在注入点使用限定符[@Default] - WELD-001408 Unsatisfied dependencies for type … with qualifiers [@Default] at injection point WELD-001408:带限定符@Default的类型验证器的依赖关系不令人满意 - WELD-001408: Unsatisfied dependencies for type Validator with qualifiers @Default WELD-001408:带有限定符 @Default 的类型 Logger 的依赖关系不满足 - WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM