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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:30:05+00:00 2026-06-17T11:30:05+00:00

Running on JBoss AS7, I have this: import javax.inject.Singleton; @Singleton public class Connections {

  • 0

Running on JBoss AS7, I have this:

import javax.inject.Singleton;

@Singleton
public class Connections {
    private final List<AtmosphereResource> connections = new ArrayList<AtmosphereResource>();

    public void add(AtmosphereResource event) {
        connections.add(event);
    }
}

and this:

import javax.inject.Inject;

public class PubSubAtmosphereHandler extends AbstractReflectorAtmosphereHandler {
    @Inject
    private Connections connections;

    @Override
    public void onRequest(AtmosphereResource event) throws IOException {
        [...]
        connections.add(event); // <---
}

NPE on the designate line. After reading countless pages and examples, this is one of the ways that is repeated dozens of times, yet it doesn’t work. I have the empty beans.xml, placed in my WEB-INF. What am I missing here ?

  • 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-17T11:30:05+00:00Added an answer on June 17, 2026 at 11:30 am

    After some research, it turns out that Atmosphere provides (currently broken) hooks for this kind of functionality. That means it IS possible to simply use your normal annotations and have it work with Atmosphere, despite the ‘foreign’ instantiation.

    If you know where your code will be deployed, you can simply overwrite the default noop InjectorProvider class from Atmosphere by having a class with the same name in the same package and having it provide the proper Injector.

    I am adding code for JBoss AS7 at the end of this answer, as well as links to code that is supposed to work on Google Guice and Spring, which I have not tested myself.

    If you need your code to work on multiple platforms, you will probably need to figure out how to detect what you are running on and then return the appropriate Injector. Since I’m not very familiar with Guice and Spring, I’ll leave that exercise to the reader.

    Dirty ‘first draft’ code for JBoss AS7 (remember that this has to go into the declared package to overwrite the default noop provider):

    package org.atmosphere.di;
    
    import java.util.NoSuchElementException;
    import java.util.ServiceLoader;
    
    import javax.enterprise.context.spi.CreationalContext;
    import javax.enterprise.inject.spi.BeanManager;
    import javax.enterprise.inject.spi.InjectionTarget;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    
    public class InjectorProvider {
    
        private InjectorProvider() {}
    
        public static Injector getInjector() {
            return LazyProvider.INJECTOR;
        }
    
        private static final class LazyProvider {
            private static final Injector   INJECTOR;
    
            static {
                Injector injector = new Injector() {
                    @Override public void inject(final Object o) {
                        try {
                            final BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
                            final CreationalContext cc = bm.createCreationalContext(null);
                            final InjectionTarget it = bm.createInjectionTarget(bm.createAnnotatedType(o.getClass()));
                            it.inject(o, cc);
                            cc.release();
                        } catch (final NamingException e) {
                            e.printStackTrace();
                        }
                    }
                };
                try {
                    injector = ServiceLoader.load(Injector.class).iterator().next();
                } catch (final NoSuchElementException e) {}
                INJECTOR = injector;
            }
        }
    }
    

    Please note that the wrapping code is taken from the Atmosphere code base, and is a very bad way to do Singletons in Java. You probably don’t want to use this ‘as is’ in production.

    Guice injector, untested: https://github.com/Atmosphere/atmosphere/blob/atmosphere-1.0.x/extras/guice/src/main/java/org/atmosphere/guice/GuiceInjector.java

    Spring injector, untested: https://github.com/Atmosphere/atmosphere/blob/atmosphere-1.0.x/extras/spring/src/main/java/org/atmosphere/spring/SpringInjector.java

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

Sidebar

Related Questions

I'm running JBoss AS7 in a standalone mode using ./standalone.sh. This binds JBOSS to
I have eclipse juno and jboss AS 7.1 final running on my machine and
We have an app running on JBoss. This app has one or two bugs
I have an application running in JBoss AS6. Authentication is working using the FORM
I have an Java application running in JBoss in which I have enabled JMX
In our Production environment we have JBoss running in a clustered mode with 4+
Now we have a project with java 1.4 and ejb 2.1 running on jboss
I have a J2EE project running on JBoss, with a maximum heap size of
We have a Web Java based application running on JBoss with allowed maximum heap
I have a Java EE 6 CDI based application running on JBoss AS 7.1.1

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.