gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:17:32 25 4
gpt4 key购买 nike

注意:我已经尝试过类似问题的可用解决方案。

我正在使用JSF,Java 8,Tomcat 9,Maven,H2 db开发一个简单的CRUD应用程序。
当我尝试启动服务器时,发生以下异常


  由以下原因引起:org.jboss.weld.exceptions.DeploymentException:WELD-001408:
  不带限定符@Default的ContactsDAO类型的依赖关系
  在注入点[BackedAnnotatedParameter]的参数1
  [BackedAnnotatedConstructor] @Inject公共
  com.contacts.ContactsController(ContactsDAO)


当我从ContactsController的构造函数中删除@Inject批注时,异常消失了,但是contactsDao为空,因此我无法获取联系人列表。

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();
}
}


}

联系人DAO.java

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


联系人DAOImpl.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

<?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不支持CDI。看看@BalusC的post

关于java - JSF-org.jboss.weld.exceptions.DeploymentException:WELD-001408:类型的依赖关系未满足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54577051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com