using Spring Expression Language (SpEL) in a blueprint container

Spring Expression Language (SpEL) can be used to configure beans in a spring application context. For example the Spring-batch framework makes heavy use of it for what they call late binding of properties. To get a feel of what SpEL can do, some examples from the spring documentation:

The prefix and suffix #{ and } in this case are just a convention and can be configured differently if you want or just leave them out

In this blog I will show how it can be used in an osgi-blueprint container. The idea is quite simple, we will use the type-converter feature from the blueprint spec to convert our SpEL expression we want to inject. If the expression is correct the result type should match the type expected by the bean. With the code given in this simple example it is not possible to access the beans from the blueprint container. That for a next post.
Here is the code:

OSGI is all about class loading so we have to configure the EvaluationContext to use the classloader associated with this bundle, this is done with a custom TypeLocator:

All this code is wired together in the blueprint.xml file:

Note the type-converters tags to register our type converter, our custom typeLocator and the SpEL expression #{ T(java.lang.Math).random() *100.0}.

Last but not least don’t forget to install the spring-expression and spring-core bundle in your osgi container when you want to deploy.

Ref:
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/expressions.html

Author: Johan Huylebroeck

blogger

blogger

Curious to know more about this topic?

Working at i8c

i8c is a system integrator that strives for an informal atmosphere between its employees, who have an average age of approx 30 years old. We invest a lot of effort in the professional development of each individual, through a direct connection between the consultants and the management (no multiple layers of middle management). We are based in Kontich, near Antwerp, but our customers are mainly located in the triangle Ghent-Antwerp-Brussels and belong to the top 500 companies in Belgium (Securex, Electrabel, UCB, etc…).

Quality Assurance

i8c is committed to delivering quality services and providing customer satisfaction. That’s why we invested in the introduction of a Quality Management System, which resulted in our ISO9001:2000 certification. This guarantees that we will meet your expectations, as a reliable, efficient and mature partner for your SOA & integration projects.

i8c - ISO9001-2015

Also worth reading

AWS AppFlow: Streamlining SaaS Integrations with AWS Services

In today’s digital world, organizations are constantly looking for ways to streamline their workflows and improve their data management processes. One of the key challenges that organizations face is integrating their various software as a service (SaaS) applications with their data management systems. This is

Read More »

Apigee Scope Validation using OpenAPI Specification

In API security and management, we often use a lot of different security mechanisms to protect the requested resource behind the API Gateway. One of these mechanisms is the validation of scopes to authorize a client on a specific sub-resource of the API. Most of

Read More »