The Java EE CDI beans is deployed in a separate jar package

Source: Internet
Author: User
Tags jboss

this blog main introduction, CDI development, all the CDI beans packaged into a jar package, how to solve org.jboss.weld.exceptions.deploymentexception:weld-001408 Unsatisfied dependencies for type [...] with qualifiers [@ ...] at injection point ... Abnormal.


Introduction

one of the main functions of Beans.xml in a CDI project is to tell the container where the CDI exists, to ensure that the container is able to scan the class files. This blog focuses on how to configure these CDI beans in a standalone jar file to be able to be loaded in a Web application.


Development Environment

1. Ubuntu 12.04

2 JDK 1.7.0.2.1

3 Weld 1.1.10

4 Tomcat 7.0.35


CDI jar File

in the previous blog we already know that developing a CDI Web application requires the Beans.xml file to be placed under the Web-inf folder to ensure that the Web container can scan and load these CDI bean class files. In the course of project development, we will package these CDI beans into a jar file and put it into the Web-inf/lib folder of the Web project, so we have to make sure that the container knows the CDI beans and scans and loads the classes. The solution to this problem is to place the Beans.xml file under the Meta-inf folder under the Jar file.


Application Testing

we use a relatively simple Web application to test this scenario. The first application is a multi-module MAVEN project that contains a CDI module in the war package of the Web module. If you do not know how to build a multi-module Web application, refer to the How to Create a multiple module project using Maven.


Application Structure

As we can see, we created a beans.xml file under the Meta-inf folder. The CDI module that is referenced when we build the Web module is referenced to the Web-inf, lib file directory. Since the jar package for the CDI module contains the Beans.xml file, the container will know where to scan the CDI files.

The CDI service interface and its implementation classes are included in the project's Lib directory, so that the implementation class can be injected into the Testservlet servlet in the Web application module.


Error Configuration Results

If we do not properly deploy the jar package containing CDI beans to the appropriate place, the initialization exception information will be thrown when the corresponding dependency is not found in the CDI initialization. If the container cannot find any dependency injection dependencies, it throws the following exception information

org.jboss.weld.exceptions.deploymentexception:weld-001408 unsatisfied dependencies for type [Service] with qualifiers [@Default] at injection point ...

The source code for this article is related to download
:java-ee-cdi-beans-deployed-in-external-library-web-inf-lib-jar-file.zip

The Java EE CDI beans is deployed in a separate jar package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.