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 6840733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:52:47+00:00 2026-05-26T23:52:47+00:00

When I inject EJB 3.1 beans into POJO created by @Inject then injection works.

  • 0

When I inject EJB 3.1 beans into POJO created by @Inject then injection works. When I construct POJO on my own then it doesn’t (Glassfish v3). Is it correct behavior?

My classes (in EJB module):

@Singleton
@LocalBean
@Startup
@Named
public class NewSingletonBean {

    @PostConstruct
    public void init(){
        System.out.println("NewSingletonBean INIT");
    }

}

_

public class MyPOJO {
        @Inject NewSingletonBean newSingletonBean;

        public void sth(){
            System.out.println("EJB injected into POJO: " + (newSingletonBean != null));
        }
}

This does not work:

@Singleton
@LocalBean
@Startup
@DependsOn(value="NewSingletonBean")
public class NewSingletonBean2 {

    @Inject NewSingletonBean newSingletonBean;

    @PostConstruct
    public void init(){
        System.out.println("NewSingletonBean2 INIT");
        System.out.println("EJB injected into EJB: " + (newSingletonBean != null));
        MyPOJO p = new MyPOJO();
        p.sth();
    }

}

_

And this works OK:

@Singleton
@LocalBean
@Startup
@DependsOn(value="NewSingletonBean")
public class NewSingletonBean2 {

    @Inject NewSingletonBean newSingletonBean;
    @Inject MyPOJO p;
    @PostConstruct
    public void init(){
        System.out.println("NewSingletonBean2 INIT");
        System.out.println("EJB injected into EJB: " + (newSingletonBean != null));
        p.sth();
    }

}

I’m using NetBeans 7.0.1.

dist directory structure:

│   CDITest.ear
│
└───gfdeploy
    └───CDITest
        ├───CDITest-ejb_jar
        │   │   .netbeans_automatic_build
        │   │   .netbeans_update_resources
        │   │
        │   ├───META-INF
        │   │       beans.xml
        │   │       MANIFEST.MF
        │   │
        │   └───tries
        │           MyPOJO.class
        │           NewSingletonBean.class
        │           NewSingletonBean2.class
        │
        ├───CDITest-war_war
        │   │   index.jsp
        │   │
        │   ├───META-INF
        │   │       MANIFEST.MF
        │   │
        │   └───WEB-INF
        │       └───classes
        │               .netbeans_automatic_build
        │               .netbeans_update_resources
        │
        └───META-INF
                MANIFEST.MF

Unpacked EAR structure:

│   CDITest-ejb.jar
│   CDITest-war.war
│
└───META-INF
        MANIFEST.MF

Unpacked EJB module jar structure:

├───META-INF
│       beans.xml
│       MANIFEST.MF
│
└───tries
        MyPOJO.class
        NewSingletonBean.class
        NewSingletonBean2.class

Is it correct behavior?

  • 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-05-26T23:52:48+00:00Added an answer on May 26, 2026 at 11:52 pm

    The following part might be an answer to your question:

    As per CDI 1.0 specification:

    3.7. Bean constructors

    When the container instantiates a bean class, it calls the bean
    constructor
    . The bean constructor is a constructor of the bean class.

    The application may call bean constructors directly. However, if the
    application directly instantiates the bean
    , no parameters are passed
    to the constructor by the container; the returned object is not bound
    to any context; no dependencies are injected by the container; and
    the lifecycle of the new instance is not managed by the container.

    HTH!

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

Sidebar

Related Questions

Is it possible to inject EJB 3.1 beans into POJO using CDI on Glassfish
Is there a way to inject EJB 3 stateless session beans into struts 2
Is it possible to inject ejb's into pojo's using the @EJB annotation? If it
I'm trying to inject Spring beans into an EJB using @Interceptors(SpringBeanAutowiringInterceptor.class) but I cannot
With the new EJB 3.1 spec is it possible to inject an EJB into
Currently I am trying to inject a stateless EJB into a CDI managed controller
Here is a very strange behavior using EJB beans: @Local public interface Provider {
Is is possible to inject IPrincipal using Castle Windsor into my asp.net mvc controller.
I want to inject some Json into the Html page returned by the server?
Problem: How to inject my own response stream to currently running iexplore.exe window.. Explation:

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.