Skip to content
Sebastian Hoß edited this page Oct 3, 2013 · 3 revisions

To use CDI together with SpEL, declare the following dependencies

<dependencies>
  <dependency>
    <groupId>com.github.sebhoss.contract</groupId>
    <artifactId>contract-cdi</artifactId>
    <version>${contracts-version}</version>
  </dependency>
  <dependency>
    <groupId>com.github.sebhoss.contract</groupId>
    <artifactId>contract-spel</artifactId>
    <version>${contracts-version}</version>
  </dependency>
</dependencies>

then expose the provided @SpEL ContractContextFactory as the @Default ContractContextFactory

import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;

import com.github.sebhoss.contract.annotation.SpEL;
import com.github.sebhoss.contract.verifier.ContractContextFactory;

class ContractContextFactoryProducer {

    @Produces
    @Default
    ContractContextFactory contextFactory(final @SpEL ContractContextFactory spelFactory) {
        return spelFactory;
    }

}

and annotate your business methods as usual using SpEL. Consult the example project for more details.

Clone this wiki locally