CDI 2, JAX-RS and dependent libraries support Table of Contents Introduction CDI 2 support

Tomcat Home
The Apache Software Foundation
Apache Tomcat 9
Version 9.0.34, Apr 3 2020
Links

Docs Home
FAQ
User Comments

User Guide

1) Introduction
2) Setup
3) First webapp
4) Deployer
5) Manager
6) Host Manager
7) Realms and AAA
8) Security Manager
9) JNDI Resources
10) JDBC DataSources
11) Classloading
12) JSPs
13) SSL/TLS
14) SSI
15) CGI
16) Proxy Support
17) MBeans Descriptors
18) Default Servlet
19) Clustering
20) Load Balancer
21) Connectors
22) Monitoring and Management
23) Logging
24) APR/Native
25) Virtual Hosting
26) Advanced IO
27) Mavenized
28) Security Considerations
29) Windows Service
30) Windows Authentication
31) Tomcat's JDBC Pool
32) WebSocket
33) Rewrite
34) CDI 2 and JAX-RS
35) GraalVM Support

Reference

Release Notes
Configuration
Tomcat Javadocs
Servlet 4.0 Javadocs
JSP 2.3 Javadocs
EL 3.0 Javadocs
WebSocket 1.1 Javadocs
JASPIC 1.1 Javadocs
Common Annotations 1.3 Javadocs
JK 1.2 Documentation

Apache Tomcat Development

Building
Changelog
Status
Developers
Architecture
Functional Specs.
Tribes

CDI 2, JAX-RS and dependent libraries support
Table of Contents

Introduction
CDI 2 support
JAX-RS support
Eclipse Microprofile support

Introduction

CDI and JAX-RS are dependencies for many other APIs and libraries. This guide explains how to add support for them in Tomcat using two optional modules that are provided in the Tomcat sources.
CDI 2 support

CDI 2 support is provided by the modules/owb optional module. It packages the Apache OpenWebBeans project and allows adding CDI 2 support to the Tomcat container. The build process of the module uses Apache Maven, and is not available as a binary bundle as it is built using a number of publicly available JARs.

The process to build CDI support is the following.

cd $TOMCAT_SRC/modules/owb
mvn clean && mvn package

The resulting JAR at target/tomcat-owb-x.y.z.jar (where x.y.z depends on the Apache OpenWebBeans version used during the build) should then be placed into the lib folder of the Tomcat installation.
CDI support can then be enabled for all webapps in the container by adding the following listener in server.xml nested inside the Server element:

The listener will produce a non fatal error if the CDI container loading fails.
CDI support can also be enabled at the individual webapp level by adding the following listner to the webapp context.xml file nested inside the Server element:

JAX-RS support

JAX-RS support is provided by the modules/cxf optional module. It packages the Apache CXF project and allows adding JAX-RS support to individual webapps. The build process of the module uses Apache Maven, and is not available as a binary bundle as it is built using a number of publicly available JARs. The support depends on CDI 2 support, which should have previously been installed at either the container or webapp level.

The process to build JAX-RS support is the following.

cd $TOMCAT_SRC/modules/cxf
mvn clean && mvn package

The resulting JAR at target/tomcat-cxf-x.y.z.jar (where x.y.z depends on the Apache CXF version used during the build) should then be placed into the /WEB-INF/lib folder of the desired web application.

If the CDI 2 support is available at the container level, the JAR can also be placed in the Tomcat lib folder, but in that case the CXF Servlet declaration must be individually added in each webapp as needed (it is normally loaded by the web fragment that is present in the JAR). The CXF Servlet class that should be used is org.apache.cxf.cdi.CXFCdiServlet and should be mapped to the desired root path where JAX-RS resources will be available.
Eclipse Microprofile support

ASF artifacts are available that implement Eclipse Microprofile specifications using CDI 2 extensions. Once the CDI 2 and JAX-RS support is installed, they will be usable by individual webapps.

The following implementations are available (reference: org.apache.tomee.microprofile.TomEEMicroProfileListener) as Maven artifacts which must be added to the webapp /WEB-INF/lib folders:

Configuration: Maven artifact: org.apache.geronimo.config:geronimo-config CDI extension class: org.apache.geronimo.config.cdi.ConfigExtension
Fault Tolerance: Maven artifact: org.apache.geronimo.safeguard:safeguard-parent CDI extension class: org.apache.safeguard.impl.cdi.SafeguardExtension
Health: Maven artifact: org.apache.geronimo:geronimo-health CDI extension class: org.apache.geronimo.microprofile.impl.health.cdi.GeronimoHealthExtension
Metrics: Maven artifact: org.apache.geronimo:geronimo-metrics CDI extension class: org.apache.geronimo.microprofile.metrics.cdi.MetricsExtension
OpenTracing: Maven artifact: org.apache.geronimo:geronimo-opentracing CDI extension class: org.apache.geronimo.microprofile.opentracing.microprofile.cdi.OpenTracingExtension
OpenAPI: Maven artifact: org.apache.geronimo:geronimo-openapi CDI extension class: org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension
Rest client: Maven artifact: org.apache.cxf:cxf-rt-rs-mp-client CDI extension class: org.apache.cxf.microprofile.client.cdi.RestClientExtension
JSON Web Tokens: Note: Fore reference only, unusable outside Apache TomEE; Maven artifact: org.apache.tomee:mp-jwt CDI extension class: org.apache.tomee.microprofile.jwt.cdi.MPJWTCDIExtension

Copyright © 1999-2020, The Apache Software Foundation

发布了133 篇原创文章 · 获赞 191 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/105731007
CDI