Bean Validation Component

Available as of Camel 2.3

The Validation component performs bean validation of the message body using the Java Bean Validation API (JSR 303). Camel uses the reference implementation, which is Hibernate Validator.

Maven users will need to add the following dependency to their pom.xml for this component:

    <!-- use the same version as your Camel core version -->

URI format




Where something must be present to provide a valid url
You can append query options to the URI in the following format, ?option=value&option=value&...

URI Options

Option Default Description
group javax.validation.groups.Default The custom validation group to use.
messageInterpolator org.hibernate.validator.engine.
Reference to a custom javax.validation.MessageInterpolator in the Registry.
traversableResolver org.hibernate.validator.engine.resolver.
Reference to a custom javax.validation.TraversableResolver in the Registry.
constraintValidatorFactory org.hibernate.validator.engine.
Reference to a custom javax.validation.ConstraintValidatorFactory in the Registry.

ServiceMix4/OSGi Deployment.

The bean-validator when deployed in an OSGi environment requires a little help to accommodate the resource loading specified in JSR303, this was fixed in Servicemix-Specs 1.6-SNAPSHOT.


Assumed we have a java bean with the following annotations
public class Car {

    private String manufacturer;

    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    private String licensePlate;
    // getter and setter

and an interface definition for our custom validation group
public interface OptionalChecks {

with the following Camel route, only the @NotNull constraints on the attributes manufacturer and licensePlate will be validated (Camel uses the default group javax.validation.groups.Default).


If you want to check the constraints from the group OptionalChecks, you have to define the route like this


If you want to check the constraints from both groups, you have to define a new interface first
@GroupSequence({Default.class, OptionalChecks.class})
public interface AllChecks {

and then your route definition should looks like this


And if you have to provide your own message interpolator, traversable resolver and constraint validator factory, you have to write a route like this

<bean id="myMessageInterpolator" class="my.ConstraintValidatorFactory" />
<bean id="myTraversableResolver" class="my.TraversableResolver" />
<bean id="myConstraintValidatorFactory" class="my.ConstraintValidatorFactory" />


It's also possible to describe your constraints as XML and not as Java annotations. In this case, you have to provide the file META-INF/validation.xml which could looks like this

<?xml version="1.0" encoding="UTF-8"?>

and the constraints-car.xml file

<?xml version="1.0" encoding="UTF-8"?>
<constraint-mappings xmlns:xsi=""
	xsi:schemaLocation=" validation-mapping-1.0.xsd"
	<bean class="CarWithoutAnnotations" ignore-annotations="true">
		<field name="manufacturer">
			<constraint annotation="javax.validation.constraints.NotNull" />
		<field name="licensePlate">
			<constraint annotation="javax.validation.constraints.NotNull" />
			<constraint annotation="javax.validation.constraints.Size">
				<element name="min">5</element>
				<element name="max">14</element>

See Also

© 2004-2011 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram