br.com.caelum:vraptor-cdi-provider

VRaptor CDI Provider

Categories

Categories

IDE Development Tools
GroupId

GroupId

br.com.caelum
ArtifactId

ArtifactId

vraptor-cdi-provider
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

VRaptor CDI Provider
Project URL

Project URL

https://github.com/caelum/vraptor-cdi-provider
Source Code Management

Source Code Management

http://github.com/caelum/vraptor-cdi-provider

Download vraptor-cdi-provider

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.caelum/vraptor-cdi-provider/ -->
<dependency>
    <groupId>br.com.caelum</groupId>
    <artifactId>vraptor-cdi-provider</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.caelum/vraptor-cdi-provider/
implementation 'br.com.caelum:vraptor-cdi-provider:1.0.0'
// https://jarcasting.com/artifacts/br.com.caelum/vraptor-cdi-provider/
implementation ("br.com.caelum:vraptor-cdi-provider:1.0.0")
'br.com.caelum:vraptor-cdi-provider:jar:1.0.0'
<dependency org="br.com.caelum" name="vraptor-cdi-provider" rev="1.0.0">
  <artifact name="vraptor-cdi-provider" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.caelum', module='vraptor-cdi-provider', version='1.0.0')
)
libraryDependencies += "br.com.caelum" % "vraptor-cdi-provider" % "1.0.0"
[br.com.caelum/vraptor-cdi-provider "1.0.0"]

Dependencies

compile (5)

Group / Artifact Type Version
br.com.caelum : vraptor jar 3.5.2
org.apache.deltaspike.cdictrl : deltaspike-cdictrl-api jar 0.4
org.apache.deltaspike.cdictrl : deltaspike-cdictrl-weld jar 0.4
org.apache.deltaspike.core : deltaspike-core-api jar 0.4
org.apache.deltaspike.core : deltaspike-core-impl jar 0.4

provided (7)

Group / Artifact Type Version
org.jboss.weld.se : weld-se-core jar 2.0.3.Final
javax.inject : javax.inject jar 1
javax.ejb : ejb-api jar 3.0
javax.enterprise : cdi-api jar 1.1
javax.annotation : javax.annotation-api jar 1.2
javax.servlet.jsp : jsp-api jar 2.1
org.mortbay.jetty : servlet-api jar 3.0.20100224

test (8)

Group / Artifact Type Version
br.com.caelum : vraptor jar 3.5.2-SNAPSHOT
org.slf4j : slf4j-simple jar 1.6.4
org.mockito : mockito-core jar 1.8.5
junit : junit jar 4.10
org.hamcrest : hamcrest-core jar 1.2
org.hamcrest : hamcrest-library jar 1.2
javax.validation : validation-api jar 1.1.0.Final
joda-time : joda-time jar 1.6

Project Modules

There are no modules declared in this project.

vraptor-cdi-provider

A Container Provider for VRaptor 3 based on CDI 1.1

In order to use the CDI Provider with VRaptor you have to follow the steps below:

1- Add the vraptor-cdi-provider entry in your pom.xml

<dependency>
	<groupId>br.com.caelum</groupId>
	<artifactId>vraptor-cdi-provider</artifactId>
	<version>1.0.0</version>
</dependency>

Change VRaptor version to 3.5.3 with cdi classifier.

<dependency>
	<groupId>br.com.caelum.vraptor</groupId>
	<artifactId>vraptor</artifactId>
	<version>3.5.3</version>
	<classifier>cdi</classifier>
</dependency>

2- Configure the Provider in web.xml

<context-param>
	<param-name>br.com.caelum.vraptor.provider</param-name>
	<param-value>br.com.caelum.vraptor.ioc.cdi.CDIProvider</param-value>
</context-param>

3- Configure the Listener that has to make BeanManager availabe in ServletContext. If you are in a Servlet Container, this listener must be placed after Weld Listener.

<listener>
	<listener-class>br.com.caelum.vraptor.ioc.cdi.BeanManagerSetup</listener-class>
</listener>

4- Create the beans.xml file in WEB-INF:

<?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"
       version="1.1" bean-discovery-mode="all">
            
</beans>

5- If you want to override any VRaptor component you must use the @Alternative + @Priority annotations. For instance:

@Alternative
@Priority(Interceptor.Priority.APPLICATION)
public class CustomPathResolver extends DefaultPathResolver{

	@Inject
	public CustomPathResolver(FormatResolver resolver) {
		super(resolver);
	}

	@Override
	protected String getPrefix() {
		return "/WEB-INF/paginas/";
	}
}

6- CDI implementations obligate you to use a Zero Args constructor for every bean that is non Dependent Scope. So instead of obligate users to create this constructor, a Java Agent is used to instrument all classes on the load time of Server. This is the same approach used by other projects, like New Relic, JProfile etc... Download it here: https://github.com/caelum/vraptor-cdi-provider/blob/master/cdiagent.jar?raw=true

7- To enable the CDI agent, you have to provide this VM argument when starting up the server:

-javaagent:path/to/cdiagent.jar

8- VRaptor provides some components that, maybe, are already provided for Application Servers. HttpServletRequest, HttpSession. Other examples are Bean Validation classes, like Validator and ValidatorFactory. In order to use Validator and ValidatorFactory you must declare them as alternatives on beans.xml.

<alternatives>
	<class>br.com.caelum.vraptor.validator.MethodValidatorFactoryCreator</class>
	<class>br.com.caelum.vraptor.validator.ValidatorCreator</class>
</alternatives>

9- List of tested servers

  • WildFly
  • Tomcat 7.0.x
  • Jetty 8.
br.com.caelum

Caelum

Versions

Version
1.0.0