01/10/2018, 17:39

Lỗi trong lúc deploy web application java JSF

Mọi người cho mình hỏi sao nó lỗi vậy . Mình mới học cái này viết cái đơn giản mà deploy nó lỗi như sau

[2018-09-23 08:53:27,619] Artifact bigquestion:war exploded: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Injector with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject public synchronized org.sonatype.guice.bean.locators.DefaultBeanLocator.add(Injector)
at org.sonatype.guice.bean.locators.DefaultBeanLocator.add(DefaultBeanLocator.java:68)
. Please see server.log for more details.

Phân cấp thư mục:
image

Lớp BeanService

    package test;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedList;

@Named
@SessionScoped
public class BeanService implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private TestInterface testImp;

    private LinkedList<TestBean> testBeanLinkedList;

    @PostConstruct
    private void init() {
        testBeanLinkedList = testImp.getTestBeans();
        System.out.println("Hello world");
    }

    public LinkedList<TestBean> getTestBeanLinkedList() {
        return testBeanLinkedList;
    }

    public void setTestBeanLinkedList(LinkedList<TestBean> testBeanLinkedList) {
        this.testBeanLinkedList = testBeanLinkedList;
    }

    public String printAll() {
        final String s = Arrays
                .toString(
                        getTestBeanLinkedList()
                                .toArray()
                );

        return s;
    }
}

Lớp TestBean

    package test;

import java.io.Serializable;

public class TestBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private String test;

    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}

Lớp TestImp

    package test;

import javax.enterprise.context.ApplicationScoped;
import java.util.LinkedList;

@ApplicationScoped
public class TestImp implements TestInterface {

    private LinkedList<TestBean> testBeanLinkedList;

    public TestImp() {
        testBeanLinkedList = new LinkedList<>();

        TestBean testBean = new TestBean();
        TestBean testBean1 = new TestBean();
        TestBean testBean2 = new TestBean();
        TestBean testBean3 = new TestBean();

        testBean.setTest("Hello 1");
        testBean1.setTest("Hello 11");
        testBean2.setTest("Hello 12");
        testBean3.setTest("Hello 13");

        testBeanLinkedList.add(testBean);
        testBeanLinkedList.add(testBean1);
        testBeanLinkedList.add(testBean2);
        testBeanLinkedList.add(testBean3);
    }

    @Override
    public LinkedList<TestBean> getTestBeans() {
        return testBeanLinkedList;
    }
}

Interface TestInterface

package test;

import java.util.LinkedList;

public interface TestInterface {
    LinkedList<TestBean> getTestBeans();
}

file index.xhtml

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
HTML
- Standard HTML UI component
Facelets
- Templating for HTML
Core
- Listeners, converters, validators, Ajax and more
Composite components
- Creating composite components
-->
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:cc="http://xmlns.jcp.org/jsf/composite"
>
   <f:view>
      <h:outputLabel value="Hello, world"/>
      <h:outputLabel value="#{(beanService.printAll)}"/>
   </f:view>
</html>

Thanks và nhờ mn giúp mình

Trương Tấn Phát viết 19:41 ngày 01/10/2018
stackoverflow.com
Antoine Sabot-Durand

WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default

jsf, java-ee, dependency-injection, cdi
answered by Antoine Sabot-Durand on 06:40AM - 06 Feb 15
Bài liên quan
0