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

  • Home
  • SEARCH
  • 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 6837275
In Process

The Archive Base Latest Questions

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

Is it possible to inject EJB 3.1 beans into POJO using CDI on Glassfish

  • 0

Is it possible to inject EJB 3.1 beans into POJO using CDI on Glassfish v3?

My classes (in EJB module):

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

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

}

_

@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();
    }

}

_

public class MyPOJO {
        @Inject NewSingletonBean newSingletonBean;

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

Server output:

Launching GlassFish on Felix platform
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
INFO: Grizzly Framework 1.9.31 started in: 31ms - bound to [0.0.0.0:4848]
INFO: Grizzly Framework 1.9.31 started in: 109ms - bound to [0.0.0.0:8080]
INFO: Grizzly Framework 1.9.31 started in: 62ms - bound to [0.0.0.0:8181]
INFO: Grizzly Framework 1.9.31 started in: 141ms - bound to [0.0.0.0:3700]
INFO: Grizzly Framework 1.9.31 started in: 0ms - bound to [0.0.0.0:7676]
INFO: GlassFish Server Open Source Edition 3.1 (43) startup time : Felix (2 812ms), startup services(1 172ms), total(3 984ms)
INFO: JMXStartupService: Started JMXConnector, JMXService URL = service:jmx:rmi://9.167.213.195:8686/jndi/rmi://9.167.213.195:8686/jmxrmi
INFO: Hibernate Validator 4.1.0.Final
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Grizzly Framework 1.9.31 started in: 16ms - bound to [0.0.0.0:8080]
INFO: Grizzly Framework 1.9.31 started in: 16ms - bound to [0.0.0.0:8181]
INFO: SEC1002: Security Manager is OFF.
INFO: SEC1010: Entering Security Startup Service
INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
INFO: SEC1011: Security Service(s) Started Successfully
INFO: WEB0169: Created HTTP listener [http-listener-1] on host/port [0.0.0.0:8080]
INFO: WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]
INFO: WEB0169: Created HTTP listener [admin-listener] on host/port [0.0.0.0:4848]
INFO: WEB0171: Created virtual server [server]
INFO: WEB0171: Created virtual server [__asadmin]
INFO: WEB0172: Virtual server [server] loaded default web module []
INFO: Portable JNDI names for EJB NewSingletonBean2 : [java:global/CDITest/CDITest-ejb/NewSingletonBean2!tries.NewSingletonBean2, java:global/CDITest/CDITest-ejb/NewSingletonBean2]
INFO: Portable JNDI names for EJB NewSingletonBean : [java:global/CDITest/CDITest-ejb/NewSingletonBean!tries.NewSingletonBean, java:global/CDITest/CDITest-ejb/NewSingletonBean]
INFO: WELD-000900 ${parsedVersion (osgiVersion})
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: NewSingletonBean INIT
INFO: NewSingletonBean2 INIT
INFO: EJB injected into EJB: true
INFO: EJB injected into POJO: false
INFO: WEB0671: Loading application [CDITest#CDITest-war.war] at [CDITest-war]
INFO: CDITest was successfully deployed in 3 531 milliseconds.

Note lines:

INFO: EJB injected into EJB: true
INFO: EJB injected into POJO: false

So it looks like @Inject into EJB works fine, but into POJO doesn’t. What am I doing wrong?
I’ve tried on GlassFish 3.1 and 3.0.1 (with NetBeans 7.0.1).

EDIT:
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
  • 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:27:29+00:00Added an answer on May 26, 2026 at 11:27 pm

    I’m not very familiar with CDI but I guess if you’re creating the POJO object yourself, no injection will happen. Did you try:

    @Inject
    private MyPOJO p;
    

    Instead of:

    MyPOJO p = new MyPOJO();  
    

    ?

    • 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's into pojo's using the @EJB annotation? If it
Is is possible to inject IPrincipal using Castle Windsor into my asp.net mvc controller.
With the new EJB 3.1 spec is it possible to inject an EJB into
Is it possible to inject Spring beans into an RestEasy @Path class? I managed
Is it possible to inject Spring beans directly into ZK backing beans? In tutorials
Is it possible to inject a request-scoped CDI bean into a Stateless session bean?
Is it possible to inject an interface into an existing 3rd party class that
Is it possible to inject an instance of logger class object using Managed Extensibility
I was wondering if its possible to inject a thread into a remote app
Is it possible to have Spring inject the JPA entityManager object into my DAO

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.