Code Monkey home page Code Monkey logo

Comments (13)

mnesarco avatar mnesarco commented on June 16, 2024

from cdi.

zappee avatar zappee commented on June 16, 2024

Thank you for the reply. I am checking that java project.

from cdi.

zappee avatar zappee commented on June 16, 2024

Thanks. It works like a charm ;)
The only one thing what I do not understand is why I need to have this fake TestBean? It is not used by anyone but if I delete it then I get a exception:

Could you please explain it to me?

[2017-02-15T16:26:35.641+0100] [Payara 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=32 _ThreadName=http-listener-1(5)] [timeMillis: 1487172395641] [levelValue: 900] [[
  StandardWrapperValve[com.remal.mybatis.demo.web.servlet.DemoServlet]: Allocate exception for servlet com.remal.mybatis.demo.web.servlet.DemoServlet
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EmployeeMapper with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject com.remal.mybatis.demo.web.servlet.DemoServlet.employeeMapper
  at com.remal.mybatis.demo.web.servlet.DemoServlet.employeeMapper(DemoServlet.java:0)

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

from cdi.

zappee avatar zappee commented on June 16, 2024

I do not have any index page. I only have a servlet.
If I remove @dependent from Mapper class and delete completely this TestBean then CDI does not work.

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

Hi @zappee, I have tested this in payara with the TestBean removed and it worked. but you can't remove @dependent from the mapper unless you set bean discovery to all in the bean.xml.

from cdi.

zappee avatar zappee commented on June 16, 2024

Please find attached your modified project. You can see my modification on the "Version Controll" tab.

source-code-is-removed

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

Hi @zappee , I got it. Looks like Weld does not detect the mapper if not used by at least one proper CDI bean. (Servlets are not proper CDI beans). So a workaround is to annotate the servlet with @dependent by now.

from cdi.

zappee avatar zappee commented on June 16, 2024

Hi @mnesarco ,
Thank you for the workaround!
Do you think it is worth to rise an issue on Paraya / Weld website and ask the guys fix that?

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

Looks like an old Weld issue with JEE components, but seems that it was fixed long time ago. So I leave the link for reference: https://issues.jboss.org/browse/JBAS-8281?page=com.atlassian.jira.plugin.system.issuetabpanels%3Achangehistory-tabpanel

Old, but maybe related: https://issues.jboss.org/browse/WELD-302

from cdi.

mnesarco avatar mnesarco commented on June 16, 2024

Ok, CDI Injection works well in Glassfish/Payara, there is a sample project ready to depoly and test here: https://github.com/mnesarco/mybatis-cdi-samples/

The special case of injecting mappers ONLY in JEE components that are not CDI aware is not related to mybatis-cdi but it is an issue in the CDI container.

The case is:

Scenario:

  1. Inject a mapper X in a Servlet
  2. Do not inject this mapper X in any valid CDI bean

Problem:

  • CDI Dependency resolution fails

Cause:

  • Payara (Weld) does not detect the InjectionTarget because there are no CDI beans requesting it.

Workaround:

  • Annotate the servlet with @dependent or any stereotype, to allow Weld to mark it as a CDI aware bean and fire proper ProcessInjectionTarget event.

from cdi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.