Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDI injection does not work in WebSphere Application Server 8.5.5.5 #19

Closed
isaiasbsf opened this issue Jul 23, 2015 · 33 comments
Closed

Comments

@isaiasbsf
Copy link

I have a web application with JSF 2.0, mybatis-3.3.0 and mybatis-cdi-1.0.0-beta2. The following two cases does not work running on WebSphere Application Server 8.5.5.5:

@Inject
private SqlSession session;

or

@Inject
@Mapper
private InerfaceXXXMapper mapper;

Eclipse IDE gives me a warning at the @Inject mentioned above:
"No bean is eligible for injection to the injection point [JSR-299 §5.2.1]"

I have a Producer method with ApplicationScoped:

@ApplicationScoped
@produces
public SqlSessionFactory produceFactory() {...}

When I run my application on WebSphere Liberty Profile V8.5 it works since it does not have injection points validation at start up. When the application is accessed the @produces method is called and the factory is loaded with session and mapper proxies.This scenario works fine.

However, when I run my application on the Application Server Full, it uses the OpenWebBeans CDI Container and it tries to validate all injection points at startup, but does not find any class of type "SqlSession" or "InerfaceXXXMapper" being produced. The type produced is "SqlSessionFactory" that holds the proxys for SqlSession and its Mappers registred.

Here is the exception I get at start up:

[7/23/15 16:33:42:226 BRT] 000000b0 WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting...
[7/23/15 16:33:44:486 BRT] 000000b0 Extension I MyBatis CDI Module - Activated
[7/23/15 16:33:46:196 BRT] 000000b0 BeansDeployer E BeansDeployer deploy
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.apache.ibatis.session.SqlSession] is not found with the qualifiers

How can I make it work?

Thanks,

Isaias

@hazendaz
Copy link
Member

Possibly using @any might work.

Sent by Outlook for Android

On Thu, Jul 23, 2015 at 1:47 PM -0700, "isaiasbsf" notifications@github.com wrote:
I have a web application with JSF 2.0, mybatis-3.3.0 and mybatis-cdi-1.0.0-beta2. The fllowing two cases does not work running on WebSphere Application Server 8.5.5.5:

@Inject
private SqlSession session;

or

@Inject
@Mapper
private InerfaceXXXMapper mapper;

Eclipse IDE gives me a warnning at the @Inject mentioned abouve:
"No bean is eligible for injection to the injection point [JSR-299 §5.2.1]"

I have a Producer method with ApplicationScoped:

@ApplicationScoped
@produces
public SqlSessionFactory produceFactory() {...}

When I run my application on WebSphere Liberty Profile V8.5 it woks since it does not have injection points validation at start up. When the application is acessed the @produces method is called and the factory is loaded with session and mapper proxys.This cenario works fine.

But when I run my application on the Application Server Full, it uses the OpenWebBeans CDI Container and it tries to validate all injection points at startup and does not find any class of type "SqlSession" or "InerfaceXXXMapper" being produced. The type produced is "SqlSessionFactory" that holds the proxys for SqlSession and its Mappers registred.

How can I make it work?

Thanks,

Isaias


Reply to this email directly or view it on GitHub:
#19

@isaiasbsf
Copy link
Author

I got the same resut:

@Inject
@Any
private SqlSession session;

[7/23/15 20:42:56:172 BRT] 0000007e WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting...
[7/23/15 20:42:58:058 BRT] 0000007e Extension I MyBatis CDI Module - Activated
[7/23/15 20:42:58:673 BRT] 0000007e BeansDeployer E BeansDeployer deploy
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.apache.ibatis.session.SqlSession] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Any()]

@hazendaz
Copy link
Member

Is your producer class also scoped in application scope?

Sent by Outlook for Android

On Thu, Jul 23, 2015 at 5:05 PM -0700, "isaiasbsf" notifications@github.com wrote:
I got the same resut:

@Inject
@Any
private SqlSession session;

[7/23/15 20:42:56:172 BRT] 0000007e WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting...
[7/23/15 20:42:58:058 BRT] 0000007e Extension I MyBatis CDI Module - Activated
[7/23/15 20:42:58:673 BRT] 0000007e BeansDeployer E BeansDeployer deploy
javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.apache.ibatis.session.SqlSession] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Any()]


Reply to this email directly or view it on GitHub:
#19 (comment)

@isaiasbsf
Copy link
Author

I wasn´t, but now it is and didn´t work.

@ApplicationScoped
public class SqlSessionFactoryProvider {

@ApplicationScoped
@produces
public SqlSessionFactory produceFactory() {...}

It seems like it needs to load the factory at startup so that it doesn´t fail the following validation. Is there a way to load the factory at startup?

at org.apache.webbeans.util.InjectionExceptionUtils.throwUnsatisfiedResolutionException(InjectionExceptionUtils.java:92)
at org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:96)
at org.apache.webbeans.container.InjectionResolver.checkInjectionPoints(InjectionResolver.java:189)
at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1161)
at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:394)
at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:332)
at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:183)
at org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplication(WebContainerLifecycle.java:78)
at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)
at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)
at com.ibm.ws.webbeans.services.JCDIServletContainerInitializer.onStartup(JCDIServletContainerInitializer.java:85)

@ilkomiliev
Copy link

It doesn't work for me too. I'm on WAS 8.5.5.3 with mybatis-cdi 1.0.0-beta3. Same errors at start-up.

@mnesarco
Copy link
Member

Hi @isaiasbsf and @ilkomiliev thanks for reporting this, can you give a try with beta5? Take into accout there are breaking changes: http://www.mybatis.org/cdi/changes.html

@mnesarco
Copy link
Member

I have tested beta5 with Payara 4.1 (Glassfish 4.1), TomEE-Plus 7.0.1, WildFly 10.1.0
Please take a look at the code (bare minimum): https://github.com/mnesarco/mybatis-cdi-samples
Can you please test it against WAS?

@mcbeelen
Copy link
Contributor

mcbeelen commented Jan 28, 2017

In version beta6 (SNAPSHOT for now) a fix for issue #40 was implemented, which solved the UnsatisfiedResolutionException in WebBeans. This fix might solve the WebSphere issues as well.
Could you please verify?

  1. Please build the cdi-project locally.
  2. Upgrade the version of the mybatis-cdi dependency to 1.0.0-beta6-SNAPSHOT in your application.
  3. Adjust your code to adapt to the breaking changes: http://www.mybatis.org/cdi/changes.html
  4. Deploy your application.
  5. Test and provide feedback.

Cheers,
Marco

@mnesarco
Copy link
Member

Hi @isaiasbsf , @ilkomiliev , can you help us testing if beta6 fixed the issue?

@ilkomiliev
Copy link

ilkomiliev commented Feb 17, 2017 via email

@isaiasbsf
Copy link
Author

Hi,

We had to look for another solution since it took too long to solve. However, I got a copy of the project from the time we were using MyBatis CDI, upgraded my dependencies to mybatis-3.4.2.jar / mybatis-cdi-1.0.0-beta6.jar and adjusted the code to the breaking changes:

@Mapper annotation is now mandatory in Mapper Interfaces and forbidden in injection points.
@SessionFactoryProvider is now mandatory in SqlSessionFactory producers.

The server started up ok, but when I tried to access a bean which injects a service that has a Mapper interface injected, I get the following error:

Caused by: java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(CDIUtils.java:47)
at org.mybatis.cdi.SerializableMapperProxy.getMapper(SerializableMapperProxy.java:60)
at org.mybatis.cdi.SerializableMapperProxy.(SerializableMapperProxy.java:47)
at org.mybatis.cdi.MyBatisBean.create(MyBatisBean.java:116)
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:93)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:81)
at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:179)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:154)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:114)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:108)
at br.com.sodexo.araras.gestaosistema.gestaoacesso.mbean.PesquisarUsuarioMBean_$$javassist_10.loadView(PesquisarUsuarioMBean$$_javassist_10.java)

@mnesarco
Copy link
Member

Hi @isaiasbsf ,

Caused by: java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)

Sounds like a container / configuration problem. Do you have a bean.xml file properly placed? Can you share your code? I am trying to solve this in the darkness.

@isaiasbsf
Copy link
Author

isaiasbsf commented Feb 22, 2017

Yes I do. CDI is working in the project, except for the bean I changed to inject the Mapper interface directly in the new way according to the breaking changes. My project uses JSF with @ConversationScoped beans.

In my SqlSessionFactoryProvider.java I have two providers:

@ApplicationScoped
@produces
@ArarasFactory
@SessionFactoryProvider
public SqlSessionFactory produceArarasFactory() {...}

@ApplicationScoped
@produces
@ArarasSegFactory
@SessionFactoryProvider
public SqlSessionFactory produceArarasSegFactory() {...}

@ArarasFactory and @ArarasSegFactory are just qualifiers to resolve ambiguities.

In my conversationScoped bean I have:

@nAmed
@ConversationScoped
public class CadastroUsuarioMBean {
....
@Inject
private UsuarioService service;

In my service implementation I have:

public class UsuarioServiceImpl implements UsuarioService, Serializable {
....
@Inject @ArarasSegFactory UsuarioMapper usuarioMapper;

In this Mapper interface I Have:

@Mapper
public interface UsuarioMapper extends Serializable {
....
}

If I change the service implementation to inject the SqlSessionFactory instead of the Mapper interface it works, but than I lose the transactional features of MyBatisCDI, which is the reason I wanted to use.

public class UsuarioServiceImpl implements UsuarioService, Serializable {
....
@Inject @ArarasSegFactory SqlSessionFactory sessionFactorySeg;
....
sessionFactorySeg.openSession().getMapper(UsuarioMapper.class).buscarUsuarios(param);

@mnesarco
Copy link
Member

Ok. Sounds like a "Passivation issue with the Conversation Scope" I have commited a fix for Issue #45 and it can be related. Please try beta7-snapshot. It works with payara and tomee.

@isaiasbsf
Copy link
Author

I didn't find beta7 in Maven central.

@hazendaz
Copy link
Member

@mnesarco Please take a look at the change I made to make serialization tests pass. If that seems appropriate, I can release beta7.

@isaiasbsf Are you ok if we force java 7 usage?

@isaiasbsf
Copy link
Author

isaiasbsf commented Feb 24, 2017

No problem, we're already using Java 7.

@mnesarco
Copy link
Member

@hazendaz your addition is ok. (I have removed Serializable by accident)

@hazendaz
Copy link
Member

@isaiasbsf I have released 1.0.0-beta7. It should be available via poms immediately and will show in maven central in a couple of hours. Can you try this again and let us know if it works? Thanks.

@isaiasbsf
Copy link
Author

@hazendaz I changed to beta 7 but got the same error:

Caused by: java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(CDIUtils.java:46)
at org.mybatis.cdi.SerializableMapperProxy.getMapper(SerializableMapperProxy.java:57)
at org.mybatis.cdi.SerializableMapperProxy.(SerializableMapperProxy.java:44)
at org.mybatis.cdi.MyBatisBean.create(MyBatisBean.java:116)
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:93)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:70)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:862)
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:742)
at org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:136)
at org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:59)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectField(AbstractInjectionTargetBean.java:387)
at org.apache.webbeans.component.AbstractInjectionTargetBean.injectFields(AbstractInjectionTargetBean.java:324)
at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:95)
at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:76)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:181)
at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:81)
at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:179)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:144)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:154)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:114)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:108)

@mnesarco
Copy link
Member

mnesarco commented Mar 1, 2017

@isaiasbsf This is very strange. It works with OpenWebBeans in Tomee. Can you deploy the Sample App just to see if it works? (https://github.com/mnesarco/mybatis-cdi-samples/). TomEE uses OpenWebBeans 1.6.3, maybe WAS uses some different version?

@mnesarco
Copy link
Member

mnesarco commented Mar 1, 2017

@isaiasbsf @hazendaz I have tested it today with WebSphere Application Server Version 16.0.0.4 Liberty and it works out of the box.

@isaiasbsf
Copy link
Author

isaiasbsf commented Mar 2, 2017

We're using the WebSphere Application Server 8.5.5.3 (Liberty Profile) for development and WebSphere Application Server 8.5.5.5 (Full application server) on production environment. I deployed the sample App (https://github.com/mnesarco/mybatis-cdi-samples/) and got the following error when accessing the web context:

Caused by: javax.servlet.ServletException: SRVE0320E: O filtro [SampleWebFilter] foi localizado, mas ocorreu uma falha na injeção de recursos.
... 3 more
Caused by: com.ibm.wsspi.injectionengine.InjectionException: Unable to obtain an instance for @Inject java.lang.reflect.Field.userMapper: java.lang.NoClassDefFoundError: javax/enterprise/inject/spi/CDI
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1123)
... 1 more
Caused by: java.lang.NoClassDefFoundError: javax/enterprise/inject/spi/CDI
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(CDIUtils.java:46)
at org.mybatis.cdi.SerializableMapperProxy.getMapper(SerializableMapperProxy.java:57)
at org.mybatis.cdi.SerializableMapperProxy.(SerializableMapperProxy.java:44)
at org.mybatis.cdi.MyBatisBean.create(MyBatisBean.java:116)
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(ThirdpartyBeanImpl.java:93)
... 1 more

@mnesarco
Copy link
Member

mnesarco commented Mar 2, 2017 via email

@mnesarco
Copy link
Member

mnesarco commented Mar 2, 2017

@isaiasbsf @hazendaz WAS CDI support started in 8.5.5 (CDI 1.0 I suppose), but it was updated to CDI 1.2 in 8.5.5.6.
ref: https://www.ibm.com/support/knowledgecenter/SS7JFU_8.5.5/com.ibm.websphere.wdt.doc/topics/wdt_overview.htm

You need at least CDI 1.1 to use mybatis-cdi.

@isaiasbsf
Copy link
Author

isaiasbsf commented Mar 2, 2017

It's true, we're using cdi-1.0 since it is the CDI version supported on our version of the application server. I understand now that MyBatis-CDI minimal compliance is cdi-1.1. However, we're not upgrading our application server at this time because of this. The CDI container works for everything else, except for MyBatis CDI. This issue was opened almost 2 years ago and we were using the latest version of WebSphere Application Server at the time. As I said before, we switched to another solution (MyBatis-Guice) and I was just trying to help solve the problem with our version. When we decide to upgrade our application server in the future, we'll consider switching back to MyBatis-CDI.
Thanks for your time.

@hazendaz
Copy link
Member

hazendaz commented Mar 2, 2017 via email

@mnesarco
Copy link
Member

mnesarco commented Mar 2, 2017

@isaiasbsf @hazendaz Ok Guys, Thanks for your help. I am closing this now. I have updated the README with info about the CDI versions supported.

@mnesarco mnesarco closed this as completed Mar 2, 2017
@znzlspt17
Copy link

I have an UnsatisfiedResolutionException problem with the mapper like isaiasbspf.

Was there a solution to this problem afterwards?

@hazendaz
Copy link
Member

@znzlspt17 What version of WAS and mybatis-cdi are you using? Based on this thread, you need to be at cdi 1.1 which is least supported version. We have profiles in pleace on github actions to run through all configuration needs from 1.1 to 2.0 with various java configurations. Those are known supported. This thread was in regards to WAS 8.5.5.5 which I'm guessing from context here was still cdi 1.0. I'd sort of hope you were not still trying to use that as it is long vulnerable and well over 5 years old based at this point in time.

@znzlspt17
Copy link

znzlspt17 commented Jun 21, 2022

@hazendaz hello im using mybatis 3.5.9, mybatis-cdi 1.1.2, owb 2.0.17, aries cdi 1.1.5 using on java 11 base karaf 4.3.7 Should I create a new post?

@hazendaz
Copy link
Member

@znzlspt17 Yes open new ticket with stack trace of issue you are facing. This ticket is specific to WAS and legacy usage which was noted as resolved in indicating newer version necessary. The library usage you have looks ok.

@znzlspt17
Copy link

@hazendaz Hello, I opened a new ticket. #302 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants