Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:08:52+00:00 2026-06-18T10:08:52+00:00

Assuming I have a data access object that I’ve already written, I’d like to

  • 0

Assuming I have a data access object that I’ve already written, I’d like to be able to use CDI to inject that into say, a service class. Furthermore, I have two implementations of that DAO.

My understanding of CDI is that I’d have to annotate my DAO implementation class so that CDI would know which implementation to inject.

The problem is, the DAO is in a .jar file. By annotating it with CDI annotations, I’m using JavaEE imports in a non-JavaEE class.

For example, let’s say I have the following class

public class BusinessService {
    @Inject @SomeMybatisQualifier AccountDAO accountDao;
    ...
}

The @Inject annotation comes from javax.inject.Inject. Now, this service class is dependent on a JavaEE environment.

Can someone please explain to me what I’m missing? How do I inject a non-annotated class into another non-annotated class? This is fairly simple with Spring.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:08:53+00:00Added an answer on June 18, 2026 at 10:08 am

    I agree with LightGuard if there’s enough classes. But for a couple, why not just produce them with @Produces?

    Here’s a decent example of implementing your own producer:

    Depedency inject request parameter with CDI and JSF2

    You should be able to write return new MyObject(); and you can add whatever qualifiers you want

    Not sure what’s unclear but here’s the gist of things: For CDI to scan a jar for beans it must have a beans.xml. Else it will not be scanned and thus not available for injects.A String is not available either. If you try to inject a String say;

    @Inject
    String myString;
    

    CDI will have no clue what to give you just like your jar. But I know what String I want (a requestparam) and I can let CDI know as well. How? Well I supply a qualifier @RequestParam to my producer (see example again) and now when I want to use it in client code I do it like this:

    @Inject
    @RequestParam
    String myString;
    

    You can do the same thing. Have a producer and just create a new instance of whatever you need and then return it. Now CDI will know just how to dependency inject that particular bean.

    Now say you have 40 classes. Then it gets messy to produce them and you want to make sure it gets scanned instead. Then you write your own little extension, observe when CDI is about to scan and instruct it to scan additional jars. Such extension is probably easy to write but I don’t know the details because I have not written any extensions like it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some code that archives data from a Microsoft Access database into a
In Android, assuming that I have files in /data/data/package.name/, without knowing the names or
Assuming I have to use C (no C++ or object oriented compilers) and I
We have an interesting challenge. We have to control access to data that reside
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
I have some Ruby web apps that use OpenID for authentication and store the
I have a data access class with an Enum called Salutation: public enum Salutation
I have a login script that verifies a username/password against data in a 'user'
I have adopted a project that has several object literals defined - mostly for
First is it dumb to use DJango as a quick/dirty data access method? We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.