Using bean validation within the app server requires a JSR-303 spec API library, the bean validation provider library(ies), and any supporting libraries. If you'd like to test drive bean validation with JPA 2.0, the WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API 2.0 does not include a bean validation API or provider, but it does include a provision for wiring one in yourself. The wiring is pretty simple and is briefly explained in this IBM Infocenter document Using Bean Validation with JPA. With the information provided in the article, I was able to configure WebSphere Application Server to use Apache's Bean Validation provider using these steps.
- Install WebSphere Application Server V7 with the Fixpack required for the feature pack (currently 7.0.0.9). There is a free Developer's Edition if you don't have the V7 test server for RAD 7.5 or an extra license lying about. :-)
- Install the WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API 2.0.
- Download the Apache Bean Validation Spec API jar. Save to a location such as:
/opt/apache/specs/geronimo-validation_1.0_spec-1.1.jar - Download the Apache Bean Validation Core jar. Save to a location such as:
/opt/apache/bval/bval-core-0.1-incubating.jar - Download the Apache Bean Valdation JSR-303 jar. Save to a location such as:
/opt/apache/bval/bval-jsr303-0.1-incubating.jar - Download Apache Commons Bean Utils. Extract the distribution and locate commons-beanutils-1.8.3.jar. Copy the jar to a location such as:
/opt/apache/commons/commons-beanutils-1.8.3.jar - Download Apache Commons Lang 2.4. Extract the distribution and locate commons-lang-2.4.jar. Copy the jar to a location such as:
/opt/apache/commons/commons-lang-2.4.jar - Start the app server.
- Open the WebSphere Integrated Solutions Console in your browser (http://<server:port>/admin).
- In the navigation pane expand Servers -> Server Types and click on WebSphere application servers.
- Select the server profile to configure. Typically server1 in a default single server environment.
- Under the Server Infrastructure section, select Process Definition.
- Under the Additional Properties section, select Java Virtual Machine.
- Under the Additional Properties section of the JVM settings, select Custom properties.
- Click New and add a property named com.ibm.websphere.validation.api.jar.path and set the value to the location of the bean validation API jar. (ex. /opt/apache/specs/geronimo-validation_1.0_spec-1.1.jar)
- Restart the application server.
The application server is now configured to locate and load the bean validation spec API jar. The spec API classes are now available, but the application server (being an EE5 app server) does include a bean validation provider. You need to make a provider available to your application by either bundling it with your application archive (in the proper location within a war or ear) or via a shared library. Include the bean validation core, bean validation jsr-303 component, commons bean utils, and commons lang 2.4 jars within the application or shared library and you'll be off to the races.
That's all there is to configuring the application server. To actually build applications which take advantage of bean validation constraints, you'll need to specify the spec API library in the build path of your tooling. The examples in Apache Bean Validation Primer will help you get started. The example in the primer is targeted for a JSE environment (I'm working on a JEE version -- no ETA), but the JPA entities, constraints, validators, and logic can be easily ported to an EE environment. One additional very important item to note is that your persistence.xml must be updated to version 2.0 in order for bean validation to be enabled by the JPA provider (OpenJPA). Since the 2.0 schema is backward compatible, it is typically a simple one line XML change. The JPA Integration section of the primer contains the rationale for this requirement and an example.
-Jeremy
1 comment:
Thanks for sharing such a great blog
Vermicompost Manufacturers | Vermicompost Suppliers
Vermicompost in chennai | Vermicompost manufacturers in Chennai
Best Vermicompost in chennai | Best vermicompost in madurai
Vermicompost manufacturers in Tamilnadu | Vermicompost in Tamilnadu
Vermicompost in Coimbatore
Post a Comment