2

I'm testing my application using junit and OpenEJB container to provide context for my beans. It's finding all beans from classpath and starting them. Unfortunatelly there are some beans I would like to remove from context, so I can replace those beans with other implementations, mocking certain functionalities.

I'm aware of openejb.deployments.classpath.exclude property. I even tried to use it as follows properties.put("openejb.deployments.classpath.exclude", ".*/CommonCache.*"); as it was sugested in this SO question.

OpenEJB sees this property but bean is still starting as shown in logs below.

Using 'openejb.deployments.classpath.exclude=.*/CommonCacheBean.*'
Auto-deploying ejb CommonCacheBean: EjbDeployment(deployment-id=CommonCacheBean)
Jndi(name="java:global/ejbs/CommonCacheBean!my.package.ICommonCache")
Created Ejb(deployment-id=CommonCacheBean, ejb-name=CommonCacheBean, container=Default Stateless Container)

So there is my question. Is there a way to exclude single bean(s) from OpenEJB context? It doesn't matter to me if it will be achieved this config way or by manual operations in java code.

Dcortez
  • 3,716
  • 1
  • 23
  • 29

1 Answers1

0

If anyone is interested i didn't manage to remove beans from context. Although there is an unbind() method in context it does not seem to work on OpenEJB context. I succeded in replacing beans manually with rebind() but it was too late because they were already injected into another beans.

They way i solved my problem was by using annotaion @Alternative on mock implementation. I also had to add entries in beans.xml to show container those beans and change the way I inject them from @EJB to @Inject.

Dcortez
  • 3,716
  • 1
  • 23
  • 29